3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 7.2.0 - 7.3.0rc3
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 5.6.0 - 5.6.30, hhvm-3.21.3, 7.0.0 - 7.1.20
Notice: Undefined variable: str in /in/4mqff on line 14 array(1) { [0]=> NULL }
Output for hhvm-3.22.0
Notice: Undefined variable: str in /in/4mqff on line -1 array(1) { [0]=> NULL }
Output for hhvm-3.18.5
Notice: Undefined variable: str in /in/4mqff on line 14 Warning: explode() expects parameter 2 to be string, null given in /in/4mqff on line 4 array(1) { [0]=> NULL }