3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = "1 -4 5 6 -2"; $e = ""; $m = "-"; for($i = 0, $len = strlen($str); $i < $len; $i++) { if($m == $str[$i]) { $e = $m; } else { $e = ""; } if(is_numeric($str[$i])) { $result[] = $e . $str[$i]; } } echo $result;

preferences:
42.18 ms | 402 KiB | 5 Q