我得到数据数组让我这样混淆:
{
"error":0,
"productcount":"1",
"page":1,
"totalpage":1,
"result":[sorry hidden cust request]
}
我想将它转换为html表,怎么样?请帮帮我......
答案 0 :(得分:2)
只需迭代您的结果,请注意您显示的数据是JSON对象,您需要先将其转换为数组:
<?php
// this has to be in JSON format
$dataArray = json_decode($yourJSON);
$dataArray = $dataArray["result"][0]["stok"];
?>
<table>
<tr>
<td><strong>Ukuran</strong></td>
<?php foreach($dataArray as $item){?>
<td> <?= $item["ukuran"] ?> </td>
<?php } ?>
</tr>
<tr>
<td><strong>Stok</strong></td>
<?php foreach(dataArray as $item){?>
<td> <?= $item["stok"] ?> </td>
<?php } ?>
</tr>
</table>