Source Code:
(back to article)
<?php $array_of_objects = [(object) ['id' => 1, 'name' => 'John'], (object) ['id' => 2, 'name' => 'Jane'], (object) ['id' => 3, 'name' => 'Jim'], (object) ['id' => 4, 'name' => 'Jill']]; $specific_value = 2; $filtered_array = array_filter($array_of_objects, function ($obj) use ($specific_value) { return $obj->id == $specific_value; }); print_r($filtered_array); ?>
Result:
Report an issue