$arr = Array
(
[0] => Array
(
[PropertyID] => 11
)
[1] => Array
(
[PropertyID] => 22
)
[2] => Array
(
[PropertyID] => 33
)
[3] => Array
(
[PropertyID] => 44
)
)
$excludeIDs = Array(22, 11, 44);
期望的结果:
Array ( [0] => Array ( [PropertyID] => 33 ) )
我想在$excludeIDS
我怎么能这样做?
答案 0 :(得分:-1)
在数组中使用unset()
:
foreach($arr as $key => $value){
if(in_array($value['PropertyID'], $excludeIDs)){
unset($arr[$key]);
}
}
$arr = array_values($arr);
print_r($arr);
输出:
Array
(
[0] => Array
(
[PropertyID] => 33
)
)
答案 1 :(得分:-1)
试试这个:
<?php
$excludeIDs = array(22, 11, 44);
$counter = 0;
foreach ($arr as $key => $value) {
if (!in_array($value['PropertyID'], $excludeIDs)) {
$result_array[$counter] = $value;
$counter++;
}
}
echo '<pre>';
print_r($result_array);
echo '</pre>';
?>