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 7 of 7
  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    foreach through a double array?

    Here is my array:

    PHP Code:
    $options = array(
    "funcs" => array("standard_funcs" => 'functions'),
    "diff_funcs" => array("standard_funcs" => 'diff_functions'),
    "vars" => array("special_vars" => 'vars'),
    ); 
    I want to do a foreach through that
    Do i do something like:

    PHP Code:
    foreach ($options as $call => $filename => $classname)

    // or

    foreach ($options as $call => ($filename => $classname)) 
    or what. Is this even possible?

  • #2
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    PHP Code:
    foreach($options as $array) {
        foreach(
    $array as $value) {
        }


  • #3
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    that wont work, because I need to be able to use all three values in the same place.

  • #4
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    What output are you looking for?

  • #5
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    The example that iLLin posted should do what you want.

    PHP Code:
    foreach($options as $call => $array) {
        foreach(
    $array as $filename => $classname) {
            
    // $call, $filename and $classname are all available here.
            // first: $call = "funcs", $filename = "standard_funcs", $classname = "functions"
            // etc.
        
    }


  • #6
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Yea I was gonna post the keys, but wasn't sure of his desired output. What aedrin said up there ^^

  • #7
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    thanks that did it.


  •  

    Posting Permissions

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