How to find out if there is a nested array

I have the following array:

Array ( [0] => Array ( [country_id] => 1 ) [1] => Array ( [country_id] => 2 ) [2] => Array ( [country_id] => 3 ) ) 

I want to basically check if the value is in this array. So, if country_id = 1, then this is true, etc.

any help would be awesome!

+4
source share
2 answers
 $found = false; foreach ($your_array as $key => $element) { if (isset($element['country_id']) && ($element['country_id'] == 1)) { $found = $key; break; } } 
+6
source

There is not a single magic function in PHP that will make this a simple solution, you can use something like array_map to achieve this, but you probably would be better off just sorting through the whole array and storing records that match your criteria.

-1
source

All Articles