如何在数组中显示对象


how to display an object in an array php?

我试图显示存储在数组中的对象,但我不能让它工作下面是我得到的(这是var_dump显示给我的)

array(5) { [0]=> string(10) "04/06/2015" [1]=> string(1) "2" [2]=> string(1) "7" [3]=> string(1) "2" [4]=> object(stdClass)#64 (1) { ["ESP_Name"]=> string(11) "something" } } 
array(5) { [0]=> string(10) "03/06/2015" [1]=> string(1) "1" [2]=> string(1) "7" [3]=> string(1) "3" [4]=> object(stdClass)#64 (1) { ["ESP_Name"]=> string(11) "something else" }} 

和我已经设法显示前4项,但我不能显示对象

中的一个
<?php 
 foreach ($resulba as $i => $valor) {
echo $valor[$i][0];
echo $valor[$i][1];
echo $valor[$i][2];
echo $valor[$i][3];
echo $valor???;
}
?>

使用最后一个参数设置为true的json_decode($jsonstring, true)将不会向数据中添加stdClass对象,而是添加具有文本键的数组。这应该使访问数据更容易。

没有预料到数据源是JSON,对对象的访问很简单:

echo $valor[$i][4]; // this would be the object itself - cannot be printed
                    // but that first part is used for object access.
echo $valor[$i][4]->ESP_Name; // the only property of the object, a string
                    // properties of objects are accessed with "->" and the property name.