2016-08-03 9 views
-1

私の配列は次のようになります。Foreach内のオブジェクトにアクセスするには?

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> 

私の出力は、第五列は私の配列created_timeインデックスがDateTimeオブジェクトが含まれている中で、created_timeある私のテーブルで enter image description here です。だからループ内のDateTimeオブジェクトから日付を取得するにはどうすればよいですか?あなたの配列$poVal['created_time']でDateTimeオブジェクトを持って

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

答えて

5

created_timeは、DateTimeオブジェクトです。だから、この答えは、@のhaz` `から任意の異なる方法datetimeobject

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

1

:あなたはすなわちでそれを使用する必要がありますので

+0

formatを使用してください?? – reformed

関連する問題