此代码不断出现错误。问题是什么? 错误发生在代码的第15行
<html>
<body>
<?php
$val=array(1,1,1,1,1);
$count=1;
$average=0;
$total=0;
for ($count=0; $count<5; $count++){
$val[$count]=rand(0,10);
echo $val["$count"]."<br />";
} $count=1;
foreach($val as $count) {
$total+=$val[$count];
}
$average=$total/$count;
echo "the average is ".$average;
?>
</body>
</html>
答案 0 :(得分:1)
我认为您应该替换
$total+=$val[$count];
与
$total += $count;
其中foreach中的$ count是您在$ val数组中设置的随机数