Mr.*_*ppy 1 php arrays multidimensional-array
我有一个多维数组:
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
)
)
Run Code Online (Sandbox Code Playgroud)
我想删除与property_id以下值匹配的数组:
Array
(
[0] => 1201
[1] => 1200
[2] => 1193
)
Run Code Online (Sandbox Code Playgroud)
我想要这个结果:
Array
(
[0] => stdClass Object
(
[user_type] => U
[user_id] => 156
[property_id] => 1196
)
)
Run Code Online (Sandbox Code Playgroud)
我正在分享我所做的代码:
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++;
}
Run Code Online (Sandbox Code Playgroud)
但在那之后我得到了 Notice: Undefined offset:
知道我做错了什么。
谢谢。
尝试这个
foreach ($results as $key => $value){
if(in_array($results[$key]->property_id , $beBounceProID) )
{
unset($results[$key]);
}
}
Run Code Online (Sandbox Code Playgroud)