$arr = array(10,20,30,-100,7,8,9);
function getResult($arr) {
$n = count($arr);
$result = $arr[0];
$t = $arr[0];
for ($i = 1; $i < $n; $i++) {
echo $t . '--------';
if ($t < 0) {
$t = 0;
}
$t += $arr[$i];
echo $t . '--------';
if($t > $result)
{
$result = $t;
}
echo $result . '<br/>';
}
return $result;
}
print_r(getResult($arr));