Many ways to do this, here’s a functional one explicitly comparing the 'id'
keys:
$ids = array_map(function ($i) { return $i['id']; }, $array2);
$outarray = array_filter($array1, function ($i) use ($ids) {
return !in_array($i['id'], $ids);
});
More beginner friendly implementation, doing the same thing:
$ids = array();
foreach ($array2 as $value) {
$ids[] = $value['id'];
}
$outarray = array();
foreach ($array1 as $value) {
if (!in_array($value['id'], $ids)) {
$outarray[] = $value;
}
}
2
solved Get new JSON array from difference of to JSON array [closed]