1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP printing from multidimensional array

Discussion in 'HTML, Graphics & Programming' started by Russinating, Jul 24, 2018.

  1. Russinating

    Capodecina

    Joined: Dec 27, 2005

    Posts: 14,688

    Location: Bristol

    I'm sure the answer here is really simple but I just don't know what to search for. I've got a multidimensional array (opened from a Google Sheet) that looks something like this:

    Code:
    Array
    (
        [0] => Array
            (
                [0] => Name
                [1] => Company
            )
    
        [1] => Array
            (
                [0] => Joe Bloggs
                [1] => Overclockers UK
            )
    
        [2] => Array
            (
                [0] => Joanna Blug
                [1] => CaseKing
            )
    )
    

    I've searched the array for "Joe Bloggs" with $key = array_search($name, array_column($sheet, 0)). How do I then print what company they work for based on $key?
     
  2. Russinating

    Capodecina

    Joined: Dec 27, 2005

    Posts: 14,688

    Location: Bristol

    Yeah, nevermind, got it, after Googling all sorts of different things!

    echo $sheet[$key][1];