0

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.

2
  • You might want to use: array_walk_recursive Commented Jan 15, 2013 at 21:50
  • Note that BER isn't going to be opened for a while ;-) Sad story. Commented Jan 15, 2013 at 21:52

1 Answer 1

6
foreach($results as $key => $val){  
  $temp = current($val); # fetch first value, which is array in your example
  echo $temp['lat'];
}
Sign up to request clarification or add additional context in comments.

3 Comments

Shouldn't it be $val = current($val), or $temp['lat']?
@Supericy, mistake, i fixed.
I deliberately created $temp variable, so you can still use $val. But if you don't need it anymore, then of course, overwrite it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.