0

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???;
}
?>

1 Answer 1

3

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.