Skip to main content
edited title
Link
nbro
  • 16k
  • 34
  • 122
  • 219

in_array() and How to check if a value is in a multidimensional array

Question Protected by l'L'l
edited tags
Link
hakre
  • 199.6k
  • 55
  • 453
  • 865
fixed formatting
Source Link
jwueller
  • 31.1k
  • 5
  • 69
  • 71

I use in_array()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()in_array() when comes to the multidimensional array?

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?

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?

edited title
Link
Lightness Races in Orbit
  • 386.7k
  • 77
  • 669
  • 1.1k
Loading
Source Link
Run
  • 57.7k
  • 179
  • 470
  • 775
Loading