意见箱
恒创运营部门将仔细参阅您的意见和建议,必要时将通过预留邮箱与您保持联络。感谢您的支持!
意见/建议
提交建议

php查找某个值是否存在于多维数组中

来源:恒创科技 编辑:恒创科技编辑部
2024-02-02 20:38:59


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;

}


php查找某个值是否存在于多维数组中

上一篇: php字符串处理 下一篇: 手机怎么远程登录云服务器?