3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json_string = '{"error_code":0,"error_message":"","return_data":{"items":[{"id":462,"users":"1,36,38"},{"id":462,"users":"1,4"}]}}'; $res = json_decode($json_string, 1); $items = $res['return_data']['items']; unset($res['return_data']['items']); // unset it first, to replace a new one $new_items = array(); foreach ($items as $key => $item) { $usersArray['id'] = $item['id']; $usersArray['users'] = array(); //create a new Array $usersIdArray = explode(',', $item['users']); foreach ($usersIdArray as $key => $user) { $usersArray['users'][] = array('user_id' => $user); // another level ^ } $res['return_data']['items'][] = $usersArray; } echo json_encode($res, JSON_PRETTY_PRINT);
Output for git.master, git.master_jit, rfc.property-hooks
{ "error_code": 0, "error_message": "", "return_data": { "items": [ { "id": 462, "users": [ { "user_id": "1" }, { "user_id": "36" }, { "user_id": "38" } ] }, { "id": 462, "users": [ { "user_id": "1" }, { "user_id": "4" } ] } ] } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
63.01 ms | 407 KiB | 5 Q