所以我在将多维数组打印到表格中时遇到了一些问题。现在我
Array
(
[0] => stdClass Object
(
[id] => 00fa4033-421f-48d9-bc69-a0d9c9c4973e
[name] => Chaka
)
)
如何将此数据输出到数组。我用来打印数组的代码如下
$response = $status->getStatus('104.243.39.107');
if (!$response) {
echo '<h2>STATUS: <span class="label label-danger">Offline</span></h2>';
} else {
echo '<h2>STATUS: <span class="label label-success">Online</span></h2>';
echo "Online Players " .$response['players']."/".$response['maxplayers'];
echo '<br /><pre>';
print_r($response['sample']); //THIS LINE
echo '</pre>';
}
我尝试了很多方法来解决这个问题,但我是 php 新手。
感谢您的帮助。
最佳答案
尝试:
echo '<table><tr><th>Id</th><th>Name</th></tr>';
foreach ($response['sample'] as $player) {
echo '<tr><td>'.$player->id.'</td><td>'.$player->name.'</td></tr>';
}
echo '</table>';
关于php - 将php中的多维数组打印到html表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31946404/