如何访问数据数组中数组中的所有code's
。因为他们都有不同的名字,我无法控制。
的index.php
<?php
$getVoucherList = "https://www.planyo.com/rest/?method=list_vouchers&api_key=yourkey&resource_id=110556";
$cleanVoucherList = preg_replace("/ /", "%20", $getVoucherList);
$voucherlist = file_get_contents("$cleanVoucherList");
$voucherList = json_decode($voucherlist, true);
var_dump($voucherList['data']);
var_dump($voucherList['data']['results']['testvoucher']['code']);
foreach ($voucherList as $value){
echo "$value";
}
?>
我的var_dump();
看起来如何
https://imagebin.ca/v/3xEh0H8inuj3
答案 0 :(得分:1)
您必须遍历$voucherList['data']['results']
数组才能访问各个测试凭证代码,
// your code
foreach($voucherList['data']['results'] as $testVoucher => $testVoucherArr){
echo $testVoucherArr['code'] . '<br />';
}