$arr = array(1,2,3,4,5,6,7,8,9,10,11);
$data = seventeen($arr);
var_dump($data);
function seventeen($arr){
$st = null;
$temp = null;
$diff = null;
$data =array();
$oper =null;
foreach ($arr as $key => $value) {
$oper = $arr;
$st = $value;
unset($oper[$key]);
$data[$key] =null;
$data[$key].=$value.",";
if($st==17){
$data[$key] = $value;
continue;
}
while($st<17)
{
$diff = 17-$st;
$find = array_search($diff,$oper);
if($find!=false){
$st = $oper[$find]+$st;
$data[$key].=$oper[$find].",";
}
if($find==false){
$data[$key].=reset($oper).",";
$st = $st+reset($oper);
$hj = array_search(reset($oper), $oper);
unset($oper[$hj]);
}
}
if($st>17)
continue;
}
return $data;
}
?>
我尽量可能多的遍历结果 我这个数组用这个程序遍历出来10种组合,但是我觉得不太完善还,你可以再修改补充。
我想了想,问题还很多,我会继续思考这个问题知道给你一个满意的答复