<?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;
<?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;
转载于:https://www.cnblogs.com/xm666/p/11192106.html