Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.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 如何访问Foreach内部的对象?_Php - Fatal编程技术网

Php 如何访问Foreach内部的对象?

Php 如何访问Foreach内部的对象?,php,Php,我的数组如下所示: Array ( [id] => 196011470503479_873596956078257 [message] => #Dabur India Ltd has been ranked amongst India's Super 50 Companies by Forbes India. The annual list ranks companies that generate high returns for investors, grow their Rev

我的数组如下所示:

Array
(
[id] => 196011470503479_873596956078257
[message] => #Dabur India Ltd has been ranked amongst India's Super 50 Companies by Forbes India. The annual list ranks companies that generate high returns for investors, grow their Revenues strongly and deploy funds efficiently.
[created_time] => DateTime Object
    (
        [date] => 2016-07-29 04:00:01.000000
        [timezone_type] => 1
        [timezone] => +00:00
    )

[shares] => Array
    (
        [count] => 26
    )
PHP代码

</tbody>
    <?php
        $i = 1;
        foreach($arr['posts'] as $poInd=>$poVal){
            echo "
                <tr>
                    <td>".$i."</td>
                    <td>".$poVal['id']."</td>
                    <td>".$poVal['name']."</td>
                    <td>".$poVal['message']."</td>
                    <td>".($poVal['created_time']->date)."</td>
                    <td>".$poVal['shares']['count']."</td>
                    <td>".count($poVal['likes'])."</td>
                    <td>".count($poVal['comments'])."</td>
                </tr>
            ";
            $i++;
        }
    ?>
</tbody>

我的输出是
在我的表中,第5列是
created\u time
,在我的数组
created\u time
索引中包含一个
DateTime
对象。那么如何从
foreach
循环中的
DateTime
对象中获取日期呢?

创建的\u time
是一个
DateTime
对象,因此您应该使用它,即:

$poVal['created_time']->format('Y-m-d H:i:s')

数组中有一个datetime对象
$poVal['created\u time']
。所以使用datetimeobject


$poVal['created_time']->格式('Y-m-dh:i:s')

这个答案与
@haz
有什么不同??