dougou5844 2015-08-11 15:49
浏览 33
已采纳

将php中的多维数组打印到html表中

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.

Thanks for the help.

  • 写回答

1条回答 默认 最新

  • dongzhi9906 2015-08-11 16:11
    关注

    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>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考