3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @throws JsonException */ function alterJson(string $json): string { $data = json_decode($json, false, 512, JSON_THROW_ON_ERROR); if (empty($data->expire_user_id)) { return '{}'; } $data->expire_user_id = explode(',', $data->expire_user_id); $data->user_id = array_shift($data->expire_user_id); if ($data->expire_user_id) { $data->expire_user_id = implode(',', $data->expire_user_id); } else { unset($data->expire_user_id); } return json_encode($data, JSON_THROW_ON_ERROR); } echo alterJson(<<<JSON {"user_id":3,"created_at":"2020-10-05 04:59:05","expire_user_id":"2,1"} JSON), PHP_EOL; echo alterJson(<<<JSON {"user_id":3,"created_at":"2020-10-05 04:59:05","expire_user_id":"1"} JSON), PHP_EOL; echo alterJson(<<<JSON {"user_id":3,"created_at":"2020-10-05 04:59:05"} JSON), PHP_EOL;
Output for git.master, git.master_jit, rfc.property-hooks
{"user_id":"2","created_at":"2020-10-05 04:59:05","expire_user_id":"1"} {"user_id":"1","created_at":"2020-10-05 04:59:05"} {}

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:
36.31 ms | 405 KiB | 5 Q