$a = array( array("id"=>7, "title"=>"a"), array("id"=>5, "title"=>"z"),);$b = array( array("id"=>5, "title"=>"a"), array("id"=>1, "title"=>"z"), array("id"=>2, "title"=>"z"),);//去掉 $b中 id 在 $a 中存在的项//结果$b = array( array("id"=>1, "title"=>"z"), array("id"=>2, "title"=>"z"),);
$a = array( array("id"=>7, "title"=>"a"), array("id"=>5, "title"=>"z"),); $b = array( array("id"=>5, "title"=>"a"), array("id"=>1, "title"=>"z"), array("id"=>2, "title"=>"z"),); foreach($b as $k=>$v) foreach($a as $t) if($v['id'] == $t['id']) unset($b[$k]);print_r($b);
Array( [1] => Array ( [id] => 1 [title] => z ) [2] => Array ( [id] => 2 [title] => z ))
$a = array( array("id"=>7, "title"=>"a"), array("id"=>5, "title"=>"z"),); $b = array( array("id"=>5, "title"=>"a"), array("id"=>1, "title"=>"z"), array("id"=>2, "title"=>"z"),); foreach($b as $k=>$v) foreach($a as $t) if($v['id'] == $t['id']) unset($b[$k]);print_r($b);
Array( [1] => Array ( [id] => 1 [title] => z ) [2] => Array ( [id] => 2 [title] => z ))
foreach 不受影响
for 受影响