我不是PHP开发者。我正在使用谷歌API,我使用的后端是PHP。我正在处理一个示例,该示例返回给定邮政编码的特定距离内的位置。从PHP返回的结果集格式如下..
Array
(
[0] => Array
(
[id] => 554
[postcode] => 1225
[suburb] => Royal Exchange
[aus_post_name] => ROYAL EXCHANGE
[state] => NSW
[lat] => -33.864393
[lon] => 151.209608
)
[1] => Array
(
[id] => 559
[postcode] => 1230
[suburb] => Queen Victoria Building
[aus_post_name] => QUEEN VICTORIA BUILDING
[state] => NSW
[lat] => -33.872049
[lon] => 151.206428
)
[2] => Array
(
[id] => 714
[postcode] => 2000
[suburb] => Barangaroo
[aus_post_name] => BARANGAROO
[state] => NSW
[lat] => -33.858315
[lon] => 151.203519
)
[3] => Array
(
[id] => 715
[postcode] => 2000
[suburb] => Dawes Point
[aus_post_name] => DAWES POINT
[state] => NSW
[lat] => -33.855601
[lon] => 151.20822
)
如何循环结果集,并获取值,例如状态和郊区?
答案 0 :(得分:3)
foreach ($bigarray as $row) {
echo $row['suburb']; // suburb
echo $row['state']; // state
}
答案 1 :(得分:0)
用于循环。这是获取州和郊区数据的最佳方式..以下代码将帮助您..
$arr_var=Array
(
0 => Array
(
'id' => 554,
'postcode' => 1225,
'suburb' => 'Royal Exchange',
'aus_post_name' =>'ROYAL EXCHANGE',
'state' => 'NSW',
'lat' => -33.864393,
'lon' => 151.209608
),
1 => Array
(
'id' => 559,
'postcode' => 1230,
'suburb' => 'Queen Victoria Building',
'aus_post_name' => 'QUEEN VICTORIA BUILDING',
'state' => 'NSW',
'lat' => -33.872049,
'lon' => 151.206428,
)
);
for($i=0;count($arr_var)>$i;$i++)
{
echo " state : ".$arr_var[$i]['state'];
echo " suburb : ".$arr_var[$i]['suburb'];
}