Find in_array in multidimensional arrays in php (recursive)

To check if a value is in an array we usually use in_array($needle,$haystack)

Example, we have the following array:

$single = array("one", "two", "three", "four");

we’ll use the following expression, that will return TRUE if the value is in the array.

in_array("four", $single)

If we have the following multidimensional array:

$multi = array(array("one", "two"), array("three", "four"));

we’ll use the expression in_array_r() instead:

in_array_r("three", $multi) 

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s