Reputation: 305
i'm trying to display an object stored in an array but i can't get it to work here is what i have (that's what var_dump shows me)
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" }}
and i've managed to display the first 4 items but i can't display the one in the object
<?php
foreach ($resulba as $i => $valor) {
echo $valor[$i][0];
echo $valor[$i][1];
echo $valor[$i][2];
echo $valor[$i][3];
echo $valor???;
}
?>
Upvotes: 0
Views: 76
Reputation: 70873
Using json_decode($jsonstring, true)
with the last parameter set to true will not add stdClass
objects into the data, but arrays with textual keys. This should make accessing the data easier.
Failing to anticipate that your source of the data was JSON, the access for the object is simple:
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.
Upvotes: 3