method filter documentation in bbn\X
Filters the given array which satisfies the 'where' condition.
Example
$arr = [
['id' => 1, 'first_name' => 'John', 'last_name' => 'Doe'],
['id' => 11, 'first_name' => 'Andrew', 'last_name' => 'Williams'],
['id' => 99, 'first_name' => 'Albert', 'last_name' => 'Taylor'],
['id' => 550, 'first_name' => 'Mike', 'last_name' => 'Smith'],
['id' => 7, 'first_name' => 'Mike', 'last_name' => 'Williams'],
];
X::filter($arr, ['first_name' => 'Mike']);
// (array) [
// ['id' => 550, 'first_name' => 'Mike', 'last_name' => 'Smith'],
// ['id' => 7, 'first_name' => 'Mike', 'last_name' => 'Williams']
// ]
X::filter($arr, function ($item) {
return $item['first_name'] === 'Mike' && $item['last_name'] === 'Smith';
});
// (array) [['id' => 550, 'first_name' => 'Mike', 'last_name' => 'Smith']]
function(array $ar, $where)
{
$res = [];
$num = count($ar);
$i = 0;
while ($i < $num) {
$idx = self::find($ar, $where, $i);
if ($idx === null) {
break;
}
else{
$res[] = $ar[$idx];
$i = $idx + 1;
}
}
return $res;
}
Filters the given array which satisfies the 'where' condition. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2025
BBN Solutions