3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $arr = [3, 2, 1, 0, -1, -2, -3, -4, 10, -1, -2, -3]; var_dump(find_max_sum_interval($arr)); function find_max_sum_interval($arr) { $sum = $arr[0]; $max = $sum; for ($i = 1; $i < count($arr); $i++) { if ($sum > 0) { $sum += $arr[$i]; } else { $sum = $arr[$i]; } if ($max < $sum) { $max = $sum; } } return $max; }
based on DXQ7n
Output for 5.6.0 - 5.6.30, hhvm-3.18.4 - 3.21.0, 7.0.0 - 7.3.0rc2
int(10)