Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:在多维对象中循环_Php_Oop - Fatal编程技术网

PHP:在多维对象中循环

PHP:在多维对象中循环,php,oop,Php,Oop,我使用PDO从数据库中获取数据,在PHP中循环对象和子对象时需要帮助 我有一个像这样的对象: array (size=2) 0 => object(stdClass)[5] public 'id' => string '5' (length=1) public 'title' => string 'Google Chrome' (length=13) public 'slug' => string 'google-chro

我使用PDO从数据库中获取数据,在PHP中循环对象和子对象时需要帮助

我有一个像这样的对象:

array (size=2)
  0 => 
    object(stdClass)[5]
      public 'id' => string '5' (length=1)
      public 'title' => string 'Google Chrome' (length=13)
      public 'slug' => string 'google-chrome' (length=13)
      public 'content' => string 'Download Chrome browser for free.....' (length=37)
      public 'excerpt' => string '' (length=0)
      public 'logo' => null
      public 'status' => string 'draft' (length=5)
      public 'views' => string '0' (length=1)
      public 'category_id' => string '0' (length=1)
      public 'created_at' => string '2017-06-12 16:59:22' (length=19)
      public 'updated_at' => string '2017-06-12 16:59:22' (length=19)
  1 => 
    object(stdClass)[10]
      public 'id' => string '6' (length=1)
      public 'title' => string 'Avast' (length=5)
      public 'slug' => string 'avast' (length=5)
      public 'content' => string 'Avast antivirus is ......' (length=25)
      public 'excerpt' => string 'excerpt....' (length=11)
      public 'logo' => null
      public 'status' => string 'published' (length=9)
      public 'views' => string '0' (length=1)
      public 'category_id' => string '0' (length=1)
      public 'created_at' => string '2017-06-12 17:45:18' (length=19)
      public 'updated_at' => string '2017-06-12 17:45:18' (length=19)
是否可以循环浏览结果并将其显示在表格中? 是否可以循环浏览结果并将其显示在表格中


身份证件
标题
地位
5.
谷歌浏览器
草案
6.
前卫的
出版



是的,这是可能的。你从哪里得到这个
DB
对象的?它的所有财产都是私有的。它来自一个框架吗?@不要惊慌,我有两个类:DB类执行所有查询并将数据返回给执行其他任务的软件类。此外,DB类在软件类内部被调用。它是否有一个用于公开_结果的访问器?还是DB本身就可以使用?@不要惊慌,非常感谢,你问了我一个好问题。我现在知道这有什么问题了。是的,这是可能的。你从哪里得到这个
DB
对象的?它的所有财产都是私有的。它来自一个框架吗?@不要惊慌,我有两个类:DB类执行所有查询并将数据返回给执行其他任务的软件类。此外,DB类在软件类内部被调用。它是否有一个用于公开_结果的访问器?还是DB本身就可以使用?@不要惊慌,非常感谢,你问了我一个好问题。我现在知道这有什么关系了。
<?php
function html($text) {
    return htmlspecialchars($text, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}

// php template

<table style="width:100%">
    <tr>
        <th>ID</th>
        <th>Title</th>
        <th>Status</th>
    </tr>
    <?php foreach ($rows as $row): ?>
        <tr>
            <td><?= html($row->id) ?></td>
            <td><?= html($row->title) ?></td>
            <td><?= html($row->status) ?></td>
        </tr>
    <?php endforeach; ?>
</table>