Home > Article > Backend Development > PHP determines whether specified values exist in a multidimensional array foreach(), in_array(),_PHP tutorial
Two-dimensional array
function search($keyWord, $stack) {//Determine whether to update or insert here
foreach ($stack as $key => $val) {
If (in_array($keyWord, $val)) {
return TRUE;
}
}
return FALSE;
}
Multidimensional array
www.2cto.com
function search($array, $v) {
$data = array();
foreach ($array as $key => $value) {
If (is_array($value)) {
$result = test($value, $v);
If (!empty($result)) {
$data[$key] = $result;
}
} else {
if ($value == $v) {
$data[$key] = $v;
}
}
}
Return $data;
}
Author heicm