3v4l.org

run code in 300+ PHP versions simultaneously
<?php function p_explode($del, $str, $cnt) { if (count(explode($del, $str) <= $cnt)) return [$str]; $tmp = explode($del, $str, $cnt); $last = array_pop($tmp); return array_merge($tmp, p_explode($del, $last, $cnt)); } $string ='1,2,3,4,5,6,7,8,9,10,11,12,13,14,15'; var_dump(p_explode(',', $str, 4));
Output for 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
Warning: Undefined variable $str in /in/4mqff on line 14 Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /in/4mqff on line 4 Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, false given in /in/4mqff:4 Stack trace: #0 /in/4mqff(14): p_explode(',', NULL, 4) #1 {main} thrown in /in/4mqff on line 4
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: Undefined variable $str in /in/4mqff on line 14 Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /in/4mqff on line 4 Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, false given in /in/4mqff:4 Stack trace: #0 /in/4mqff(14): p_explode(',', NULL, 4) #1 {main} thrown in /in/4mqff on line 4
Process exited with code 255.
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19
Warning: Undefined variable $str in /in/4mqff on line 14 Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /in/4mqff on line 4 Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /in/4mqff:4 Stack trace: #0 /in/4mqff(14): p_explode(',', NULL, 4) #1 {main} thrown in /in/4mqff on line 4
Process exited with code 255.
Output for 8.0.10 - 8.0.30
Warning: Undefined variable $str in /in/4mqff on line 14 Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /in/4mqff:4 Stack trace: #0 /in/4mqff(14): p_explode(',', NULL, 4) #1 {main} thrown in /in/4mqff on line 4
Process exited with code 255.
Output for 8.0.0 - 8.0.9
Warning: Undefined variable $str in /in/4mqff on line 14 Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, bool given in /in/4mqff:4 Stack trace: #0 /in/4mqff(14): p_explode(',', NULL, 4) #1 {main} thrown in /in/4mqff on line 4
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined variable: str in /in/4mqff on line 14 Warning: count(): Parameter must be an array or an object that implements Countable in /in/4mqff on line 4 array(1) { [0]=> NULL }
Output for 7.3.32 - 7.3.33
Warning: count(): Parameter must be an array or an object that implements Countable in /in/4mqff on line 4 array(1) { [0]=> NULL }
Output for 7.1.0 - 7.1.33
Notice: Undefined variable: str in /in/4mqff on line 14 array(1) { [0]=> NULL }

preferences:
181.61 ms | 401 KiB | 189 Q