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);

preferences:
42.37 ms | 1173 KiB | 5 Q