[英]Printing a multidimensional array in php into an html table
So I have been having some trouble printing my multi dimensional array into a table. 所以我在将多维数组打印到表格时遇到了一些麻烦。 Right now I
现在我
Array
(
[0] => stdClass Object
(
[id] => 00fa4033-421f-48d9-bc69-a0d9c9c4973e
[name] => Chaka
)
)
How can I output this data to an array. 如何将此数据输出到数组。 The code I am using to print the array is the following
我用来打印数组的代码如下
$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>';
}
I have tried many methods to fix this but I am new to php. 我已经尝试了很多方法来解决这个问题,但我是php的新手。
Thanks for the help. 谢谢您的帮助。
Try : 试试:
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>';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.