我收到错误“未定义索引:从流明调用数据时的id_currency,请帮帮我
<?php
require '../vendor/autoload.php';
$client = new GuzzleHttp\Client();
$res = $client->request('GET', 'http://139.59.113.86/zeeposapi/public/api/currency', [
'api_token' => ['']
]);
$decodedPosts = json_decode($res->getBody(), true);
?>
<?php
foreach ($decodedPosts as $post) { ?>
<tr>
<th scope="row">
<?php echo $post['id_currency']; ?>
</th>
</tr>
<?php } ?>
答案 0 :(得分:0)
错误通知&#34; id_currency&#34;在数组中不存在。
<强>输出强>
{ &#34;状态&#34;:1, &#34;数据&#34;:[ { &#34; id_currency&#34;:1 }, { &#34; id_currency&#34;:2 } ] &#34; totalCount&#34;:2 }
您应该使用以下代码
<?php foreach($decodedPosts["data"] as $post) { ?>
<tr>
<th scope="row">
<?php echo $post['id_currency']; ?>
</th>
</tr>
<?php } ?>