Forum Moderators: coopster
So
Array = ([awz001] => 7, etc...)
and the other array is a multi-dimensional
Array ( [0] => Array ( [number] => awz001 [0] => awz001 [Section] => Section one [1] => Section one )
Is there away to search the second one with the first ones array keys?
Would you do it with two loops? First through the multi then the single?
foreach($array1 as $key1 => $val1) { for($i=0;$i<sizeof($array2);$i++) { if (in_array($key1,$array2[$i])) { [$array2[$i] array contains $key1] break 2; } } } You could also try
foreach($array1 as $key1 => $val1) { for($i=0;$i<sizeof($array2);$i++) { $checkit=array_search($key1,$array2[$i]); if ($checkit) { [$checkit = matching $array2[$i] key] break 2; } } } With
array_search() it's important to note that if the array being searched uses 0 as it's first key that you use a string '0' instead of the numeral/boolean value. Apparently you can't do nested foreach() loops.
Also note that foreach() makes a copy of the array being tested, so you may experience memory issues with an especially large source array.