I have been stumped on this for hours. I need to get the initial key of the array and the id. However I am only getting 1 result returned back.
Below is example code and also here is a link - https://3v4l.org/HdMtA
In short the expected output should be.
key 11111111 id val_somevalue5555
key 2222222 id val_somevalue25
I am only getting one result.
key 11111111 id val_somevalue5555
.
$json = '[{
"11111111": {
"id": "val_somevalue5555",
"customer": {
"32312": {
"name": "john doe"
}
}
},
"2222222": {
"id": "val_somevalue25",
"customer": {
"32312234": {
"name": "jane doe"
}
}
}
}]';
$jsonarr = json_decode($json, true);
$newarr = [];
foreach($jsonarr as $value)
{
$key = key($value);
$newarr[] = ['key' => $key, 'id' => $value[$key]['id']];
}
var_dump($newarr);
Any help would be appreciated not sure if its the format of the json or what.