我不确定为什么会收到这样的未定义偏移通知:
<?php
$numbers = array('1','2','3');
$total = 0;
for($i=0;$i<=sizeof($numbers); $i++) {
$total += $numbers[$i];
echo $total;
}
?>
输出:
136注意:未定义的偏移量:第17行的E:\ php \ arrays \ array_1.php中的36
您的数组在索引0、1和2处具有三个元素。在索引3中没有元素。
您的循环应该在遇到该循环之前停止...
for($i=0;$i<sizeof($numbers); $i++) {
}
另外,结帐array_sum,可能仍然是您想要的...
$total=array_sum($numbers);
您应该循环到数组大小的<
,而不是<=
。
for($i=0;$i<sizeof($numbers); $i++) {
将您的条件从<=
更改为<
。
这将正确添加:
$total += intval($numbers[$i]);
关闭html错误
error_reporting(E_ALL);
ini_set('display_errors', 'On');
ini_set('html_errors', 'Off');
<td>
<div class="form-group">
{{Form::select('LeaveCategoryID[]',$LeaveCategory, null, ['class' => "form-control", 'placeholder' => 'Select One'])}}
</div>
</td>