I have a php object called $result (got from json_decode), below is a print_r of the object. I’m trying to echo the question number and answer. ex:
4 answer1
5 answer2
How do i go about doing this.
stdClass Object
(
[request] => stdClass Object (
[other] => stdClass Object
(
[4] => stdClass Object
(
[answer] => answer1
)
[5] => stdClass Object
(
[answer] => answer2
)
)
)
)
I’m still learning OOP. As a simple approch i tried echo $result->request->other->4->answer to echo the first answer, but that doesn’t seem to be right. Thanks for any help.
You need to wrap the number property with
{}: