php search multiple key values in array code example
Example 1: multiple value match in array php
if (in_array('a', $array_under_test) || in_array('b', $array_under_test)) {
}
Example 2: php search multidimensional array for multiple values
function multi_array_search($array, $search) {
$result = array();
foreach ($array as $key => $value){
foreach ($search as $k => $v){
if (!isset($value[$k]) || $value[$k] != $v){
continue 2;
}
}
$result[] = $key;
}
return $result;
}
print_r(multi_array_search($list_of_phones, array()));
print_r(multi_array_search($list_of_phones, array('Manufacturer' => 'Apple')));
print_r(multi_array_search($list_of_phones, array('Manufacturer' => 'Apple', 'Model' => 'iPhone 6')));