I have the following JSON on a page
{
"users": [
{
"name": "John",
"age": "30",
},
{
"name": "Dave",
"age": "20",
},
...
]
}
I'm decoding it using $json = json_decode($data);. If I want a loop that print every name and age for each user how can I do that?
I'm tring to do something like the following code but it's not working
foreach($json->users->name as $key => $result){
$name = $result;
$age = $result->age;
echo $name;
echo $age;
echo "<br>";
}
What am I doing wrong? How could I achieve that?
print_r($json->users)What do you see?