3v4l.org

run code in 300+ PHP versions simultaneously
<?php $response = '{ "status": 1, "message": "Success", "data": [ { "order": { "id_biling": "1", "order_id": "A18", "kd_bill": "001001202101200001", "order_name": "Kita", "amount": "20000" }, "detail": [ { "kd_bill": "001001202101200001", "name": "Odading", "id_item": "66", "amount": "10000", "subtot": "20000", "jml": "2" } ] } ] }'; $decoded_response = json_decode($response, true); foreach($decoded_response['data'][0] as $key=>$value){ if ($key == 'detail'){ $decoded_response['data'][0]['order'][$key] = $value; unset($decoded_response['data'][0][$key]); } } echo json_encode($decoded_response);
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
{"status":1,"message":"Success","data":[{"order":{"id_biling":"1","order_id":"A18","kd_bill":"001001202101200001","order_name":"Kita","amount":"20000","detail":[{"kd_bill":"001001202101200001","name":"Odading","id_item":"66","amount":"10000","subtot":"20000","jml":"2"}]}}]}

preferences:
154.83 ms | 407 KiB | 5 Q