Next time enable error_reporting and include any errors and warnings you get.
In this instance the issue is fairly obvious. Your array only contains a single item - and that item is an object. The echo
construct expects a string (but can handle an implicit cast from other scalar types). It doesn't know how to output the object. If the object implements the __tostring() method then PHP will call that to get a string to output. But stdClass (the type of object you have here) does not have a _tostring() method.
You also don't state in your question if you are looking for a specific value in the data - i.e. if you know its name - which is rather critical for how you approach the solution.
That you have a stdclass object suggests that you have loaded it from serialized representation of data such as JSON. If you had converted this input to an array instead of an object (most of the things in PHP which will return stdclass objects can also return associative arrays) you could simply have done this:
function walk_array($in, $depth)
{
if ($depth><MAXDEPTH) {
// because you should never use unbounded recursion
print "Too deep!\n";
return;
}
foreach ($in as $k=>$item) {
print str_pad("", $depth, "-") . $k . ":";
if (is_array($item)) {
print "\n";
walk_array($item, $depth+1);
} else {
print $item;
}
}
}
You can convert an object into an associative array with get_object_vars()