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.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Warning: Undefined variable $str in /in/N26GF on line 14 Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /in/N26GF on line 4 array(1) { [0]=> NULL }
Output for 8.0.0 - 8.0.30
Warning: Undefined variable $str in /in/N26GF on line 14 array(1) { [0]=> NULL }
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined variable: str in /in/N26GF on line 14 array(1) { [0]=> NULL }
Output for 7.3.32 - 7.3.33
array(1) { [0]=> NULL }

preferences:
228.11 ms | 401 KiB | 286 Q