= 2){ if(in_array($count, $tempArray)){ array_push($_template, $count); }else{ if($count == 5){ array_push($_template, 2); array_push($_template, 3); }else if($count == 9){ array_push($_template, 4); array_push($_template, 2); array_push($_template, 3); }else{ Calculate($_template, $count, $tempArray); } }}else{ array_push($_template, $count);}function Calculate(&$_template, $count, $tempArray){ shuffle($tempArray); while($count>=2) { $templateid = array_rand($tempArray,1); $templateValue = $tempArray[$templateid]; #echo "模板值为:{$templateValue}"; if($count >= 2){ if($count >= $templateValue){ $count = $count - $templateValue; #echo "count:{$count}"; array_push($_template, $templateValue); //echo $templateid.""; }else{ array_push($_template, $count); $count = 0; } } } if($count == 1){ $isZero = false; #echo "最后还有一个哦{$count}"; if(count($_template) >= 1){ foreach($_template as $key=>$val){ if($val <= 3 ){ #echo "最后一个处理完成"; $_template[$key] = $val+1; $isZero = true; break; } } } if($isZero == false){ #echo "只能添加一个模板了
"; array_push($_template, $count); } }}echo "最后取得的模板数组为:";var_dump($_template);?>