我正在努力显示 Country_name、country_prefix 以及 city_name 和 city_prefix 以在 PHP 中显示
Array (
[0] => stdClass Object
(
[country_name] => Russian Federation
[country_prefix] => 7
[country_iso] => RU
[cities] => Array
(
[0] => stdClass Object
(
[city_id] => 107
[city_name] => Moscow
[city_prefix] => 495
[city_nxx_prefix] =>
[setup] => 0
[monthly] => 60.9
[isavailable] => 1
[islnrrequired] => 0
)
...
上面返回 $results 数组,我目前正在使用类似的东西,但已经尝试了很多迭代。
echo '<br />Results: <br />';
foreach ($result as $countries => $country) {
foreach ($country as $details => $value) {
echo $value . "<br/>";
}
}
试试这个:
foreach($results as $country){
// country name in $country->country_name
foreach($country->cities as $city){
echo $city->city_name.'<br/>';
}
}
正如评论中告诉您的那样,您有一个对象数组。您可以使用 foreach 迭代它,但是您应该使用正确的语法访问其属性 (
->
)