Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2010
    Posts
    235
    Thanks
    39
    Thanked 6 Times in 6 Posts

    3-D array loop, Loop based on 3rd key

    This is another question that arose from the task from this thread:

    loop through 3-D array based on key conditions

    Now, I need to loop through any school that matches the name, for any city and any state.

    PHP Code:
    $school="University of Illinois";
    foreach(
    $codes[][][$school] as $school_key=>$school_value){
        

    I tried the above with no success. I need to have the loop move to the 3rd key automatically and just grab any school with that name.

    I'm trying to avoid looping through each city, then each state, then each school if possible.

    array_keys perhaps?
    Last edited by mathceleb; 06-01-2011 at 09:35 PM.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    If you don't know the city and state looping through them all like you did in your original post in the old thread is the easiest way to do that. If your array is that big you should just use a database as it would be far easier to query the data however you want.

  • Users who have thanked Inigoesdr for this post:

    mathceleb (06-01-2011)

  • #3
    Regular Coder
    Join Date
    Mar 2010
    Posts
    235
    Thanks
    39
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by Inigoesdr View Post
    If you don't know the city and state looping through them all like you did in your original post in the old thread is the easiest way to do that. If your array is that big you should just use a database as it would be far easier to query the data however you want.
    Thanks, that is a great idea.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •