php查找某个值是否存在于多维数组中
function deep_in_array($value, $array) {
foreach($array as $item) {
if(!is_array($item)) {
if ($item == $value) {
return $item;
} else {
continue;
}
}
if(in_array($value, $item)) {
return $item;
} else if($this->deep_in_array($value, $item)) {
return $item;
}
}
return false;
}
加入配置的值有多个子数组,改造下
/**
* @param $value
* @param $array
* @return bool
* 某个值是否存在于多维数组中
*/
public function deep_in_array($value, $array)
{
$total =[];
foreach ($array as $item) {
if (!is_array($item)) {
if ($item == $value) {
return $item;
} else {
continue;
}
}
if (in_array($value, $item)) {
$total[] = $item;
} else if ($this->deep_in_array($value, $item)) {
$total[] = $item;
}
}
return $total;
}
版权声明
本文仅代表作者观点,不代表博信信息网立场。