简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM