function award_sp_cal($spRzt) { $totalAward = 1; $temp = null; foreach($spRzt as $sp) { if (count($sp) == 1) { $totalAward *= array_shift($sp); } else if (count($sp) >1 ) { $temp = $totalAward; $totalAward = 0;//原理: a*x + b*x = (a+b)*x foreach($sp as $spOne) { $totalAward += ($temp*$spOne); } } } return $totalAward; } $arr = array(array(1,2,3), array(2), array(3)); //结果为array(1,2,3), array(2,2,3), array(3,2,3)的组合之和 echo award_sp_cal($arr);