3v4l.org

run code in 300+ PHP versions simultaneously
<?php $jsons[] = <<<JSON { "success": true, "msg": "", "obj": [ { "id": 1, "remark": "D" }, { "id": 159, "remark": "mssdss" } ] } JSON; $jsons[] = <<<JSON { "success": true, "msg": "", "obj": [ { "id": 14, "remark": "tttt" }, { "id": 56, "remark": "ok" } ] } JSON; $result = null; foreach ($jsons as $json) { $obj = json_decode($json); if (!$obj->success) { throw new Exception($obj->msg); } if (!$result) { $result = $obj; } else { array_push($result->obj, ...$obj->obj); } } var_export($result);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
(object) array( 'success' => true, 'msg' => '', 'obj' => array ( 0 => (object) array( 'id' => 1, 'remark' => 'D', ), 1 => (object) array( 'id' => 159, 'remark' => 'mssdss', ), 2 => (object) array( 'id' => 14, 'remark' => 'tttt', ), 3 => (object) array( 'id' => 56, 'remark' => 'ok', ), ), )

preferences:
77.29 ms | 1160 KiB | 4 Q