$arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; //PHP 5.4+
$total = 0, $i = 0;
foreach($arr as $v) {
if($v % 2 != 0) { //奇数
$total += $v;
++$i;
}
}
$total /= $i;
echo "所有奇数的平均值:" . $total;
$a=array(4,5,3,1,6,9,1,7,3);
foreach($a as $k=>$v){
if($v%2==0){
$b+=$v;
}
}
嗯。。。不会啦