I use in_array()
to check whether a value exists in an array like below,
$a = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $a))
{
echo "Got Irix";
}
//print_r($a);
but what about an multidimensional array (below) - how can I check that value whether it exists in the multi-array?
$b = array(array("Mac", "NT"), array("Irix", "Linux"));
print_r($b);
or I shouldn't be using in_array()
when comes to the multidimensional array?
var_dump(array_sum(array_map(function ($tmp) {return in_array('NT',$tmp);}, $multiarray)) > 0);
– Agnius Vasiliauskas$multiarray = array( "Hello", array("Mac", "NT"), array("Irix", "Linux"));
– Paolo$tmp
is an array withis_array()
function. If not an array - proceed with different scenario. – Agnius Vasiliauskas