当我想要
时,我想逐个回显json数组中的值<?php
function get_web_page($url) {
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false // don't return headers
);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
$response = get_web_page("http://maps.googleapis.com/maps/api/geocode/json?address=colombo");
$resArr = array();
$resArr = json_decode($response);
echo "<pre>";
print_r($resArr);
echo "</pre>";
echo "<br>";
echo "<br>";
;
?>
这是代码
上方的浏览器中的当前结果stdClass Object
(
[results] => Array
(
[0] => stdClass Object
(
[address_components] => Array
(
[0] => stdClass Object
(
[long_name] => Colombo
[short_name] => Colombo
[types] => Array
(
[0] => locality
[1] => political
)
)
[1] => stdClass Object
(
[long_name] => Colombo
[short_name] => Colombo
[types] => Array
(
[0] => administrative_area_level_2
[1] => political
)
)
[2] => stdClass Object
(
[long_name] => Western Province
[short_name] => WP
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[3] => stdClass Object
(
[long_name] => Sri Lanka
[short_name] => LK
[types] => Array
(
[0] => country
[1] => political
)
)
)
[formatted_address] => Colombo, Sri Lanka
[geometry] => stdClass Object
(
[bounds] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 6.9805844
[lng] => 79.8900852
)
[southwest] => stdClass Object
(
[lat] => 6.8625113
[lng] => 79.8225192
)
)
[location] => stdClass Object
(
[lat] => 6.9270786
[lng] => 79.861243
)
[location_type] => APPROXIMATE
[viewport] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 6.9805844
[lng] => 79.8900852
)
[southwest] => stdClass Object
(
[lat] => 6.8625113
[lng] => 79.8225192
)
)
)
[place_id] => ChIJA3B6D9FT4joRjYPTMk0uCzI
[types] => Array
(
[0] => locality
[1] => political
)
)
)
[status] => OK
)
我希望按值回显价值
答案 0 :(得分:1)