
Benjamin S. answered 11/15/19
Tutor
4.8
(110)
Lead Software Engineer Specializing in PHP
You're really close and you're exactly right, you need to use a foreach loop. Please see the code below for more insight into how to handle this situation:
$string = file_get_contents("/home/michael/test.json");
$json_a = json_decode($string, true);
foreach($json_a AS $key=>$value){
echo '<br>Name:'.$key;
echo ', Status:'.$value['status'];
if(isset($value['age'])){
echo ', Age:'.$value['age'];
}
if(isset($value['count'])){
echo ', Count:'.$value['count'];
}
if(isset($value['progress'])){
echo ', Progress:'.$value['progress'];
}
if(isset($value['bad'])){
echo ', Bad:'.$value['bad'];
}
}