Continuous Sequence that Sums Up to X

$array = [1, 1, 1, 1, 1, 1];
$target = 3;

var_dump(checkSum($array, $target));

function checkSum($array, $target)
{
    $sum = $array[0];
    $end = 0;

    foreach ($array as $start => $value) {
        while ($sum < $target) {
            $end++;

            if ($end == count($array)) {
                return false;
            }

            $sum += $array[$end];
        }

        if ($sum == $target && $end > $start) {
            print "\n[$start, $end]";
            return true;
        }
        $sum -= $array[$start];
    }
  
  return false;
}
	
index