user1974467
user1974467

Reputation: 23

PHP multidimensional array - foreach loop

I have a problem getting array values "lat" and "long" without going deeper by foreach function. Array:

array(1) {
  ["Berlin, Germany(All airports)"]=>
  array(1) {
    ["Berlin Brandenburg Willy Brandt(BER)"]=>
    array(2) {
      ["lat"]=>
      string(9) "52.366667"
      ["lon"]=>
      string(9) "13.503333"
    }
  }

}

Function:

foreach($results as $key => $val){  
  //here i want to reach lat and long without additional foreach loop
}

Thank you all for answers.

Upvotes: 0

Views: 1593

Answers (1)

Glavić
Glavić

Reputation: 43552

foreach($results as $key => $val){  
  $temp = current($val); # fetch first value, which is array in your example
  echo $temp['lat'];
}

Upvotes: 6

Related Questions