php array search multiple values code example
Example 1: 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')));
Example 2: multiple value match in array php
if (in_array('a', $array_under_test) || in_array('b', $array_under_test)) {
}
Example 3: multiple value match in array php
$uniqueKeys = array_unique($list[0])
foreach ($uniqueKeys as $uniqueKey)
{
$v = array_keys($list[0], $uniqueKey);
if (count($v) > 1)
{
foreach ($v as $key)
{
}
}
}