我有一個多維陣列:PHP未設置多維數組元素哪個密鑰值是匹配
Array
(
[0] => stdClass Object
(
[user_type] => U
[user_id] => 156
[property_id] => 1201
)
[1] => stdClass Object
(
[user_type] => U
[user_id] => 156
[property_id] => 1200
)
[2] => stdClass Object
(
[user_type] => U
[user_id] => 156
[property_id] => 1196
)
[3] => stdClass Object
(
[user_type] => U
[user_id] => 156
[property_id] => 1193
)
)
和我想刪除陣列值是匹配與property_id
:
Array
(
[0] => 1201
[1] => 1200
[2] => 1193
)
,我想這結果:
Array
(
[0] => stdClass Object
(
[user_type] => U
[user_id] => 156
[property_id] => 1196
)
)
我與我分享我的代碼:
for($b=0; $b<count($beBounceResults); $b++){
$beBounceProID[] = $beBounceResults[$b]->property_id;
}
// Getting thus array in this variable $beBounceProID
Array
(
[0] => 1201
[1] => 1200
[2] => 1193
)
$counter = "0";
foreach ($results as $key => $value){
if($results[$key]->property_id == $beBounceProID[$counter]){
unset($results[$key]);
}
$counter++;
}
但在那之後我收到Notice: Undefined offset:
任何想法,我做錯了。
謝謝。
而不是$反= 「0」;使用$ counter = 0; –
您在列表中有1193個,但仍想保留它? – Rizier123
@anantkumarsingh這沒有區別!絕對錯誤,如果它的索引爲0,它會將它隱含到int – Rizier123