The variable $id
isn’t in the scope of the function. You need to use the use
clause to make external variables accessible:
$foo = array_filter($bar, function($obj) use ($id) {
if (isset($obj->foo)) {
var_dump($id);
if ($obj->foo == $id) return true;
}
return false;
});