I have the following code to read a Json and store some values into an array:
<?php
$json = '[{
"provider_id":1,
"nro_chart":1,
"control": {
"color": "blue",
"total_value": 21.5,
"car_id": 421118
}
},
{
"control": {
"color": "green",
"total_value": 25,
"car_id": 421119
}
},
{
"control": {
"color": "red",
"total_value": 18,
"car_id": 421519
}
}
]';
$j = json_decode($data);
$result = [];
foreach ($j as $item) {
array_push($result,[
'total_value' => $item->control->total_value,
'car_id' => $item->control->car_id
]);
}
Now I need to get the two values that are outside of "control" like "provider_id" and "nro_chart" inside a variable.