【发布时间】:2021-11-08 04:08:09
【问题描述】:
首先,对不起,我是 PHP 新手,我已经搜索了解我想要做什么,但找不到任何解决方案。对于专业开发人员来说,我的问题可能看起来很简单。如果它伤害了任何专业程序员的自尊心,请不要关闭,因为任何善良的程序员都可以看到并帮助我。谢谢。
我有来自 curl http 请求的 json 数据,我将其更改为数组:
array(6) {
["page"]=>
int(2)
["per_page"]=>
int(6)
["total"]=>
int(12)
["total_pages"]=>
int(2)
["data"]=>
array(6) {
[0]=>
array(5) {
["id"]=>
int(7)
["email"]=>
string(24) "michael.lawson@reqres.in"
["first_name"]=>
string(7) "Michael"
["last_name"]=>
string(6) "Lawson"
["avatar"]=>
string(39) "https://reqres.in/img/faces/7-image.jpg"
}
[1]=>
array(5) {
["id"]=>
int(8)
["email"]=>
string(26) "lindsay.ferguson@reqres.in"
["first_name"]=>
string(7) "Lindsay"
["last_name"]=>
string(8) "Ferguson"
["avatar"]=>
string(39) "https://reqres.in/img/faces/8-image.jpg"
}
[2]=>
array(5) {
["id"]=>
int(9)
["email"]=>
string(22) "tobias.funke@reqres.in"
["first_name"]=>
string(6) "Tobias"
["last_name"]=>
string(5) "Funke"
["avatar"]=>
string(39) "https://reqres.in/img/faces/9-image.jpg"
}
[3]=>
array(5) {
["id"]=>
int(10)
["email"]=>
string(22) "byron.fields@reqres.in"
["first_name"]=>
string(5) "Byron"
["last_name"]=>
string(6) "Fields"
["avatar"]=>
string(40) "https://reqres.in/img/faces/10-image.jpg"
}
[4]=>
array(5) {
["id"]=>
int(11)
["email"]=>
string(24) "george.edwards@reqres.in"
["first_name"]=>
string(6) "George"
["last_name"]=>
string(7) "Edwards"
["avatar"]=>
string(40) "https://reqres.in/img/faces/11-image.jpg"
}
[5]=>
array(5) {
["id"]=>
int(12)
["email"]=>
string(23) "rachel.howell@reqres.in"
["first_name"]=>
string(6) "Rachel"
["last_name"]=>
string(6) "Howell"
["avatar"]=>
string(40) "https://reqres.in/img/faces/12-image.jpg"
}
}
["support"]=>
array(2) {
["url"]=>
string(34) "https://reqres.in/#support-heading"
["text"]=>
string(72) "To keep ReqRes free, contributions towards server costs are appreciated!"
}
}
我想将此数据添加到html中的表中,当我尝试存储数据时,我无法获得存储数据的真实方法。这是我的html:
<table>
<thead>
<tr>
<th>No</th>
<th>Nama Depan</th>
<th>Nama Belakang</th>
<th>ID</th>
<th>Foto</th>
</tr>
</thead>
<tbody>
<?php foreach ($profile as $pro) { ?>
<?php $no = 1; ?>
<tr>
<td><?= $no++; ?></td>
<td><?= $profile['data'][0]['first_name'] ?></td>
<td><?= $profile['data'][0]['last_name'] ?></td>
<td><?= $profile['data'][0]['id'] ?></td>
<td><?= $profile['data'][0]['avatar'] ?></td>
</tr>
<?php } ?>
</tbody>
</table>
如何正确存储嵌套数组中的数据?
【问题讨论】:
-
this 之类的东西可以让你继续前进......