如何在 php 中访问数组变量


How to access the array variable in php?

我正在尝试在对象数组中回显变量。

array(4) 
{ 
 [0]=> int(20) 
 [1]=> string(16) "Demo Blog Post 3" [2]=> string(753) "Lorem ipsum dolor sit" 
 [3]=> object(DateTime)#1 (3) 
  {
   ["date"]=> string(19) "2016-02-19 13:28:23" 
   ["timezone_type"]=> int(3) 
   ["timezone"]=> string(11) "Asia/Muscat" 
  } 
} 

我想要这个数组中的日期对象...我怎样才能得到这个... ?

 $times = $row[3]->date;     // Returning NULL
 echo count($times);         // 1
 $times = $row[3]['date'];   // Returning CodeBreak.

var_dump($row[3])

object(DateTime)#1 (3) {
  ["date"]=> string(19) "2016-02-19 13:28:23" 
  ["timezone_type"]=> int(3) 
  ["timezone"]=> string(11) "Asia/Muscat" 
 } 

var_dump(get_object_vars($row[3]))

array(3) 
{ 
  ["date"]=> string(19) "2016-02-19 13:28:23" 
  ["timezone_type"]=> int(3) 
  ["timezone"]=> string(11) "Asia/Muscat" 
} 

谢谢。。。

get_object_vars使用它可以帮助您获取给定对象的属性

喜欢这个

var_dump(get_object_vars ($row[3])['date'] );

如果你把你的数组命名为$products,你不会从$products[3]["date"]得到日期吗?