我有一个从api调用返回的数组。有时它只是一组,而其他组则是多组。下面的示例是针对“查看源”页面进行的:
[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($ response)我希望能够遍历这些项目,并在一个漂亮的列表中只回显区域和前缀。
我该怎么做?
非常感谢您的帮助。
答案 0 :(得分:1)
foreach($response["objects"] as $i=>$v)
{
echo "Region: ".$v["region"];
echo "<br>";
echo "Prefix: ".$v["prefix"];
echo "<hr>";
}