I have two different arrays (say) array1
and array2
. I want to check whether a value in array2
exists in array1
.
Array1
(
[0] => Array
(
[id] => 7
[title] => Course1
)
[1] => Array
(
[id] => 8
[title] => course2
)
[2] => Array
(
[id] => 9
[title] => course3
)
)
Array2
(
[0] => 7
[1] => 8
)
I used:
foreach ($array2 as $id) {
$found = current(array_filter($array1, function($item) {
return isset($item['id']) && ($id == $item['id']);
}));
print_r($found);
}
When I run this code it give the following error:
Undefined variable: id