| mathceleb |
05-25-2011 09:44 PM |
loop through 3-D array based on key conditions
I have a 3-D array with keys as [city][state][school]. Is there a way to loop through conditionally based on keys, so go through each school based on a city = Chicago and State = Illinois? Or do I have to do a traditional foreach and go through all values and pick off the ones that match Chicago and Illinois?
Doing the long way, I have the code below. the problem is, that 3-D array contains 6000 entries, and I have to crank through it a few thousand times.
PHP Code:
foreach ($codes as $city){
foreach ($city as $state){
foreach ($state as $school){
if ($city == "Chicago" && $state == "Illinois") {array_push($school_match,$school);}
}
}
}
|