I need to find $str in JSON
find name and result show age in JSON
{
“ID": {
“1": {
“name": A,
“age": “16"
},
“2": {
“name": B,
“age": “17"
},
}
}
I try put $str with name and need result output age
e.g.
input A output 16
my code is
$str = ‘A’;
$data = json_decode(file_get_contents('inJSON'));
foreach($data as $item) {
foreach($item->ID as $ID) {
if(ID->name == $str) {
echo age;
break;
}
}
}
didnt work
ps. sorry my English is not good.