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 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.28, 8.4.1 - 8.4.14, 8.4.16, 8.5.0 - 8.5.1
{"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"} {}
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 7.2.0 - 7.2.34
Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or heredoc end (T_END_HEREDOC) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in /in/5HESp on line 37
Process exited with code 255.

preferences:
128.89 ms | 409 KiB | 5 Q