Filter array by values in a second array Share & earn cash

You can filter rows with a set of fields with a list of values, searching in a fieild named "id" (by default). Also you can define other field if you want.


$rows = [
['id' => 14, 'name' => 'bob', 'style' => 'big', 'age' => 33, 'whim' => 'no'],
['id' => 39, 'name' => 'sue', 'style' => 'yes', 'age' => 111, 'whim' => 'yes'],
['id' => 994, 'name' => 'lucy', 'style' => 'small', 'age' => 23, 'whim' => 'no'],
['id' => 72, 'name' => 'jill', 'style' => 'big', 'age' => 22, 'whim' => 'yes'],
['id' => 15, 'name' => 'sys', 'style' => 'med', 'age' => 24, 'whim' => 'no'],
['id' => 16, 'name' => 'maj', 'style' => 'med', 'age' => 87, 'whim' => 'yes'],
['id' => 879, 'name' => 'Ike', 'style' => 'large', 'age' => 56, 'whim' => 'no'],
['id' => 286, 'name' => 'Jed', 'style' => 'big', 'age' => 23, 'whim' => 'yes'],
];

$filter = [14, 72, 8790];
$result = filter_rows($rows, $filter);

print_r($result);
// Array
//(
// [0] => Array
// (
// [id] => 14
// [name] => bob
// [style] => big
// [age] => 33
// [whim] => no
// )
//
// [3] => Array
// (
// [id] => 72
// [name] => jill
// [style] => big
// [age] => 22
// [whim] => yes
// )
//)

License type: "1 free end product". Read more.

Reviews

Nobody has rated this offer yet.