我有一個從api調用返回的數組。有時它只會是一組,而另一組則是其他組。下面的例子中,採取頁面「查看源」:PHP通過數組循環並回顯所選項目
[objects] => Array
(
[0] => Array
(
[stock] => 388
[voice_enabled] => 1
[region] => BASEL, SWITZERLAND
[voice_rate] => 0.00800
[prefix] => 61
[sms_rate] => -1
[number_type] => local
[setup_rate] => 0.80000
[rental_rate] => 0.80000
[group_id] => 25728319905588
[sms_enabled] =>
[resource_uri] => /v1/Account/MAMTE4MTHJNJRKODBIMD/AvailableNumberGroup/25728319905588/
)
[1] => Array
(
[stock] => 593
[voice_enabled] => 1
[region] => BELLINZONA, SWITZERLAND
[voice_rate] => 0.00800
[prefix] => 91
[sms_rate] => -1
[number_type] => local
[setup_rate] => 0.80000
[rental_rate] => 0.80000
[group_id] => 25732565267448
[sms_enabled] =>
[resource_uri] => /v1/Account/MAMTE4MTHJNJRKODBIMD/AvailableNumberGroup/25732565267448/
)
還有10個這樣的塊。
這是通過從下面的PHP文件的API調用生成:
<?php
include("connect.php");
include("settings.php");
require_once 'myapiprovider.php';
$p = new RestAPI($auth_id, $auth_token);
$params = array('country_iso' => 'CH');
$response = $p->get_number_group($params);
print_r($response);
?>
代替的print_r($響應)我想能夠通過項目環和回聲只是區域和前綴在一個不錯的名單。
我該怎麼做?
非常感謝您的幫助。
http://php.net/foreach –