- json_decode: documentation ( source)
- print_r: documentation ( source)
- array_walk_recursive: documentation ( source)
<?php
$requestResult = <<<EOT
{
"name": "Benjamin Clementine",
"mbid_id": "578e5d1c-be21-4158-b147-30aad67f207d",
"albums": {
"68e65535-f133-408d-93dd-205e9555eaa5": {
"albumcover": [
{
"id": "172070",
"url": "http://assets.fanart.tv/fanart/music/578e5d1c-be21-4158-b147-30aad67f207d/albumcover/at-least-for-now-55b74dfa59411.jpg",
"likes": "0"
}
]
}
}
}
EOT;
$decodedResult = json_decode($requestResult, true);
$xmlELement = new SimpleXMLElement('<root/>');
array_walk_recursive($decodedResult, array($xmlElement, 'addChild'));
print_r($xmlElement->xpath('//albumcover/url'));