3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $n = 5; $str = "1 -4 5 6 -2"; $e = ""; $m = "-"; for($i = 0, $len = strlen($str); $i < $len; $i++) { if(is_numeric($str[$i])) { $result[] = $e . $str[$i]; } else { if($m == $str[$i]) { $e = $m; } else { $e = ""; } } } for($i = 0; $i < $n; $i++) { echo $result[$i] . "\n"; }
Output for 5.6.30, hhvm-3.15.4 - 3.22.0, 7.0.0 - 7.3.0rc3
1 -4 5 6 -2