I need do extract all cpu ids from this kind of JSON response:
$response = json_decode('{
"code": 26,
"result": {
"0": {
"cpu": {
"423": {
"prod": "Intel",
"model": "i5-8300H",
},
"424": {
"prod": "Intel",
"model": "i7-8750H",
}
}
}
}
}');
I managed to obtain first id 423 with this code:
$response = $response->result;
foreach ($response as $item) {
$key = key((array)$item->cpu);
}
but I can't find the way to get the reset, in this case 424. How can I do it?
$responseassignment is not valid PHP syntax.$response = json_decode('{...}');array_keys()instead ofkey();