I've got the following object:
$json = '{"response": {"status": {"message": "Success"}, "images": [{"url": "http://domain.com/images/0001.jpg"}, {"url": "http://domain.com/images/0001.jpg"}]}}';
$obj = json_decode($json);
Then i have an array:
$obj_path = array('response', 'images');
I can access images within $obj like so $obj->$obj_path[0]->$obj_path[1]
How would i do it more dynamically? Something along the line of...
$obj_path_count = count($obj_path);
for($i=0; $i<$obj_path_count; $i++)
{
$obj_access_path .= '->' . $obj_path[$i]; //Build path to the access the object?
}
var_dump($obj . $obj_access_path); // Display object images
The above code gives the following error
Object of class stdClass could not be converted to string
$$varName)? Do you want to create more concise code? Or make decisions on which array item to pick?var_dumpshould be a comma, I believe, whence the error.