Search multidimensional array by key/value filter

Checks all elements of multidimensional array to match specified filtering array.

php
fork add to bundle source
function array_multi_search($array, $search) { return array_filter($array, function($value) use ($search) { foreach ( $search as $k => $v ) { if ( $value[$k] != $v ) return false; } return true; }); }

usage

load_function('array_multi_search'); $array = [ 0 => ['name' => 'John', 'age' => 27], 1 => ['name' => 'John', 'age' => 25], 2 => ['name' => 'Linn', 'age' => 25], ]; $found = array_multi_search($array, ['name' => 'John', 'age' => 25]); print_r($found); // Array // ( // [1] => Array // ( // [name] => John // [age] => 25 // ) // )
← how to use this in app?
create log ...inout