如何拆分 php 脚本的值并可能进行平均值


How to split the values of a php script and possibly do an average?

<html>
<body>
<h2>xxxxxx!</h2>
<?php
    $score = array();
    exec("D:'Users'Owner'Documents'a2 2>&1 D:'Users'Owner'Documents'212.wav D:'Users'Owner'Documents'StartUp'23sw1.wav", $score);
    echo '<h3>Score </h3>';
    echo '<br />';
    echo 'xxxxxxx: ' . $score[0];
?>
</body>
</html>

$score[0] 的输出类似于 21 20 11 8 79 100 89。如何拆分它们?我也有兴趣做一个平均值 = ( 21 + 20+ 11+ 8 +79 +100+ 89)/7

像这样做

$arr = explode(' ',$score[0]);
$average = array_sum($arr)/count($arr);
echo $average;

//创建一个有空格的数组,就像这样。

$scoreExp = explode(' ', $score[0]);
// start with 0 
$scorePlus = 0;
for($i=0;$i<count($scoreExp);$i++){
    $scored = $scoreExp[$i];    
    $scorePlus = $scorePlus + $scored;
}
echo $scorePlus/count($scoreExp);