PHP的多维数组 - foreach循环
问题描述:
我有一个问题,得到数组值“lat”和“long”,而不会深入foreach函数。阵列:PHP的多维数组 - foreach循环
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"
}
}
}
功能:
foreach($results as $key => $val){
//here i want to reach lat and long without additional foreach loop
}
谢谢大家的答案。
答
foreach($results as $key => $val){
$temp = current($val); # fetch first value, which is array in your example
echo $temp['lat'];
}
+1
不应该是'$ val = current($ val)'或$ temp ['lat']'? – Supericy
+1
@超级错误,我修好了。 –
+0
比你多,工作正常....是的,$ temp soulh是$ val – user1974467
您可能需要使用:[array_walk_recursive](http://stackoverflow.com/questions/526556/how-to-flatten-a-multi-dimensional-array-to-simple-one-in- php) –
请注意,BER不会打开一段时间;-)悲伤的故事。 – johannes