I’m not sure why I am getting an Undefined Offset Notice on this:
<?php
$numbers = array('1','2','3');
$total = 0;
for($i=0;$i<=sizeof($numbers); $i++) {
$total += $numbers[$i];
echo $total;
}
?>
Output:
136
Notice: Undefined offset: 3 in E:\php\arrays\array_1.php on line 17
6
Your array has three elements at index 0, 1 and 2. There is no element with index 3.
Your loop should stop before it hits that…
Also, checkout array_sum, which might be what you’re wanting anyway…