Hi,
To check if the value is included in mutlidimensional array, you can use the solution below. The function is calling itself to check if the value is included in sub-arrays. Please note that it is checking the array values, but not the array keys.
function in_multidimensional_array($value, $multidimensional_array) {
foreach ($multidimensional_array as $array_value) {
if ( $array_value == $value OR ( is_array($array_value) AND in_multidimensional_array($value, $array_value) ) ) {
return true;
}
}
return false;
}
$arr = array(1 => array("abc","def"), 2 => array("aaa","bbb"));
if ( in_multidimensional_array("aaa",$arr) ) {
echo "Value is included in array.";
}
else {
echo "Value is not included in array.";
}