元素解析错误

时间:2014-04-29 11:07:59

标签: php arrays

我想在我的PHP代码中总结一个元素范围。但是,我得到了rangetotal的解析错误。我做错了什么?

$rainData = array(0.3, 0.6, 1.2, 1.1, 0.35, 0.0, 0.25, 0.6, 0.0, 0.12, 0.23, 0.2, 0.234,
                          1.2, 0.1, 2.1, 2.45, 1.3, 0.7, 0.0, 0.0, 0.13, 0.12, 0.07, 0.1, 0.0,
                          0.8, 1.0, 0.55, 0.12, 0.5, 0.21, 1.01, 0.0, 0.0, 0.08, 0.09, 1.01, 0.76,
                          0.08, 0.3, 0.0, 0.9, 0.7, 1.3, 0.7, 0.09, 2.32, 1.28, 0.953, 0.75, 1.01);

        $traceCount= 0;
        $heavyRainCount = 0;
        $rangeTotal = 0;

        for ($i= 1; $i < sizeof($rainData); $i = $i + 1)
        {

            $Total = $Total + $rainData [$i];

        if ($rainData [$i] < 0.02)
            $traceCount = $traceCount + 1;
        if ($rainData [$i] > 2) 
            $heavyRainCount = $heavyRainCount + 1;
        }
        $avgRainfall = $Total / sizeof($rainData);
        $rangeTotal = ($rainData[26] + $rainData[27] $rainData[28] + $rainData[29] + $rainData[30]);

1 个答案:

答案 0 :(得分:0)

您在+$rainData[27]

之间缺少$rainData[28]符号

所以改成它:

$rangeTotal = ($rainData[26] + $rainData[27] + $rainData[28] + $rainData[29] + $rainData[30]);