Loading

for循环 求数组平均数和总数

<?php

$arr = ['a'=>18,20,'cc'=>10,2=>11];
$arrLen = count($arr);
$count = $sum= 0;
for($i=0;$i<$arrLen;$i++)
{
  $key = key($arr);
  $current = current($arr);
  $count++;
  next($arr);//下一个
  
  $sum +=$current;
}
echo '总数:'.$sum.'平均数是'.$sum/$count;

 

posted @ 2019-07-15 22:51  mingBolg  阅读(942)  评论(0编辑  收藏  举报