PHP Multidimensional array issue

Discussion in 'PHP' started by cringwall, Feb 26, 2010.

  1. #1
    Here is my problem.

    I have an api that returns an array, $services.

    This command: print_r($services);

    produces this:

    Array ( [blogger] => Array ( [name] => Blogger [methods] => Array ( [0] => blog [1] => images ) ) [posterous] => Array ( [name] => Posterous [methods] => Array ( [0] => blog [1] => microblog [2] => status [3] => images ) ) [tumblr] => Array ( [name] => Tumblr [methods] => Array ( [0] => blog [1] => images ) ) [typepad] => Array ( [name] => TypePad [methods] => Array ( [0] => blog [1] => microblog [2] => status ) ) [vox] => Array ( [name] => Vox [methods] => Array ( [0] => blog ) ) [wordpress] => Array ( [name] => WordPress.com [methods] => Array ( [0] => blog [1] => microblog [2] => status ) ) [xanga] => Array ( [name] => Xanga [methods] => Array ( [0] => blog [1] => microblog [2] => status ) ) )

    My question is this - how do I programmatically get to the strings in the [methods] strings above array, ie 'blog' , 'microblog', 'status'
     
    cringwall, Feb 26, 2010 IP
  2. HostingProvider

    HostingProvider Active Member

    Messages:
    1,480
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    95
    #2
    Try foreach(), using the value assigned to each value contained in [methods].
     
    HostingProvider, Feb 26, 2010 IP
  3. ThomasTwen

    ThomasTwen Peon

    Messages:
    113
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you want to access them just one time, you can use something like $services["blogger"]["methods"][0], $services["blogger"]["methods"][1], etc. BUt if you want to loop through all of them, go for foreach()
     
    ThomasTwen, Feb 27, 2010 IP
  4. Om ji Kesharwani

    Om ji Kesharwani Peon

    Messages:
    211
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    use foreach()
     
    Om ji Kesharwani, Feb 28, 2010 IP
  5. redlightshooter

    redlightshooter Greenhorn

    Messages:
    94
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    18
    #5
    use foreach() to loop the array..
     
    redlightshooter, Mar 1, 2010 IP