第15行的PHP错误我需要协助

时间:2018-10-13 13:49:19

标签: php

此代码不断出现错误。问题是什么? 错误发生在代码的第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> 

1 个答案:

答案 0 :(得分:1)

我认为您应该替换

$total+=$val[$count];

$total += $count;

其中foreach中的$ count是您在$ val数组中设置的随机数