php search multidimensional array for value code example
Example 1: php sort multidimensional array by value
function sortByOrder($a, $b) {
return $a['order'] - $b['order'];
}
usort($myArray, 'sortByOrder');
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')));