3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function chunkByDelimiter(array $data, $delimiter='-') { $result = []; while(false!==($pos=array_search($delimiter, $data)) && $segment = array_splice($data, 0, $pos)) { $result[] = $segment; array_shift($data); } return $result; } var_dump(chunkByDelimiter(['foo', '-', 'bar', 'baz', '-', 'fee', 'bee', '-']));
Output for 5.4.0 - 7.1.0
array(3) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(2) { [0]=> string(3) "bar" [1]=> string(3) "baz" } [2]=> array(2) { [0]=> string(3) "fee" [1]=> string(3) "bee" } }
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/53nK7 on line 5
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/53nK7 on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_ARRAY, expecting ')' in /in/53nK7 on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_ARRAY, expecting ')' in /in/53nK7 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/53nK7 on line 3
Process exited with code 255.