練習: 陣列儲存 55 44 33 22 11 計算總和.平均(count).最大.最小值
- $score = array(55,44,33,22,11);
- $total = 0;
- $max = 0 ;
- $min = 999 ;
-
- for($i=0;$i<count($score);$i++){
- $total = $total + $score[$i] ;
- if($score[$i]>$max){
- $max = $score[$i] ;
- }
- if($score[$i]<$min){
- $min = $score[$i];
- }
- }
- echo $total."<br>";
- echo $total/count($score)."<br>" ;
- echo $max."<br>";
- echo $min."<br>"
複製代碼 |