PHP数组上的循环
我不是PHP开发人员。我使用的是google API,我使用的后端是PHP。我正在使用一个示例,该示例返回给定zipcode一定距离内的位置。从PHP返回的结果集的格式如下PHP数组上的循环,php,Php,我不是PHP开发人员。我使用的是google API,我使用的后端是PHP。我正在使用一个示例,该示例返回给定zipcode一定距离内的位置。从PHP返回的结果集的格式如下 Array ( [0] => Array ( [id] => 554 [postcode] => 1225 [suburb] => Royal Exchange [aus_post_name] => ROYAL EXCHANGE [state] => NSW [lat] =>
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
)
如何循环结果集并获取值,例如州和郊区的值?使用或:
用于循环。这是获取州和郊区数据的最佳方式。。以下代码将对您有所帮助
$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'];
}
显示一些代码,如@JackManey所说。没关系……我自己得到了答案。去投票吧,然后把它关了…嗯,什么?它应该是foreach($bigarray作为$row),不是吗?您当前的代码毫无意义。不投反对票是因为这是一个小错误,但不投反对票是因为现在是错误的。
$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'];
}