3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = "[1,1x,1x,1x][2,2x,2x,2x]"; $arr ="[]"; preg_replace_callback('/\[(.*?)\]/', function($m) use (&$arr){ $arr[] = explode(',',preg_replace('/([\w]+)/', "[$1]", $m[1])); }, $str); print_r($arr); var_dump($arr);
Output for 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
Fatal error: Uncaught Error: [] operator not supported for strings in /in/lY5Nn:6 Stack trace: #0 [internal function]: {closure}(Array) #1 /in/lY5Nn(5): preg_replace_callback('/\\[(.*?)\\]/', Object(Closure), '[1,1x,1x,1x][2,...') #2 {main} thrown in /in/lY5Nn on line 6
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Fatal error: Uncaught Error: [] operator not supported for strings in /in/lY5Nn:6 Stack trace: #0 [internal function]: {closure}(Array) #1 /in/lY5Nn(7): preg_replace_callback('/\\[(.*?)\\]/', Object(Closure), '[1,1x,1x,1x][2,...') #2 {main} thrown in /in/lY5Nn on line 6
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Fatal error: [] operator not supported for strings in /in/lY5Nn on line 6
Process exited with code 255.

preferences:
138.04 ms | 402 KiB | 185 Q