Remove the same entry from the PHP array
$ A = array ("id" => 7, "title" => "a"), array ("id" => 5, "title" => "z"),); $ B = array ("id" => 5, "title" => ""), array ("id" => 1, "title" => "z"), array ("id" => 2, "title" => "z "),); // remove the items whose IDs exist in $ a in $ B // result $ B = array ("id" => 1, "title" => "z"), array ("id" => 2, "title" => "z "),);
Reply to discussion (solution)
$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 ))
When an item is removed from a loop, will the next loop be unaffected?
Foreach is not affected
For affected