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.

share|improve this question
You might want to use: array_walk_recursive – Ricardo Ortega Magaña Jan 15 at 21:50
Note that BER isn't going to be opened for a while ;-) Sad story. – johannes Jan 15 at 21:52
feedback

1 Answer

up vote 5 down vote accepted
foreach($results as $key => $val){  
  $temp = current($val); # fetch first value, which is array in your example
  echo $temp['lat'];
}
share|improve this answer
1  
Shouldn't it be $val = current($val), or $temp['lat']? – Supericy Jan 15 at 21:54
1  
@Supericy, mistake, i fixed. – Glavić Jan 15 at 21:56
Than you a lot, works fine.... and yes, $temp soulh be $val – user1974467 Jan 15 at 21:57
I deliberately created $temp variable, so you can still use $val. But if you don't need it anymore, then of course, overwrite it. – Glavić Jan 15 at 22:10
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.