How to filter an array of object?
You can use array_filter
with a custom callback:
function filter_callback($element) {
if (isset($element->foo) && $element->foo == 'some_value') {
return TRUE;
}
return FALSE;
}
$arr = array_filter($arr, 'filter_callback');
Want to filter an array? Use array_filter!
$new_array = array_filter($array, function($obj){
if (isset($obj->admins)) {
foreach ($obj->admins as $admin) {
if ($admin->member == 11) return false;
}
}
return true;
});