{
"listing": {
"@attributes": {
"domain": "example.com"
},
"tld": "com",
"sld": "example",
"owner": "John Smith"
}
}
I am needing to iterate through this JSON array and put the values into PHP variables so that I can return the values.
Example:
echo $sld;
would print:
example
Would I need to do this with a foreach loop (and if so how would I format this) or is there a easy built in function such as extract()
that will do this?
<?php
$json = '{
"listing": {
"@attributes": {
"domain": "example.com"
},
"tld": "com",
"sld": "example",
"owner": "John Smith"
}
}';
$decoded_array = json_decode($json, true);
echo $decoded_array['listing']['sld'];//example
?>
You can use
json_decode('your json string', true);
Which will return an associative array of your string which you can then loop though.