I have the following JSON code:
{
"google.com": {
"clicks": 23,
"browsers": {
"Chrome": 19,
"Mozilla": 2,
"Safari": 1
}
},
"mcnitro.net": {
"clicks": 87,
"browsers": {
"Chrome": 19,
"Mozilla": 2,
"Safari": 1
}
}
}
And I am endeavouring to print on the document page the arrays' names and their children. So far, I have tried the following PHP code:
<?php
header("Content-type: text/javascript");
$jsonString = file_get_contents('stats.json');
$data = json_decode($jsonString, true);
foreach($data->children() as $domain) {
echo $data[$domain];
foreach($data[$domain] as $value) {
echo $value['clicks'];
}
}
?>
However, I am facing an issue in the error_log
:
PHP Fatal error: Call to a member function children() on array in /home/gamin167/public_html/ads/engine/300x250/gen.js.php on line 5
The result wanted was to have "google.com" and "mcnitro.net" printed, as well as their "clicks" property.
Any tip or advice will be highly appreciated! Thanks in advance!