慕神8447489
您可以使用这里找到的解决方案/blok/on/070910.万一链接掉了,这是代码.。classCombinationsimplementsIterator{
protected$c=null;
protected$s=null;
protected$n=0;
protected$k=0;
protected$pos=0;
function__construct($s,$k){
if(is_array($s)){
$this->s=array_values($s);
$this->n=count($this->s);
}else{
$this->s=(string)$s;
$this->n=strlen($this->s);
}
$this->k=$k;
$this->rewind();
}
functionkey(){
return$this->pos;
}
functioncurrent(){
$r=array();
for($i=0;$ik;$i++)
$r[]=$this->s[$this->c[$i]];
returnis_array($this->s)?$r:implode('',$r);
}
functionnext(){
if($this->_next())
$this->pos++;
else
$this->pos=-1;
}
functionrewind(){
$this->c=range(0,$this->k);
$this->pos=0;
}
functionvalid(){
return$this->pos>=0;
}
protectedfunction_next(){
$i=$this->k-1;
while($i>=0&&$this->c[$i]==$this->n-$this->k+$i)
$i--;
if($i
returnfalse;
$this->c[$i]++;
while($i++k-1)
$this->c[$i]=$this->c[$i-1]+1;
returntrue;
}}foreach(newCombinations("1234567",5)as$substring)
echo$substring,'';12345 12346 12347 12356 12357 12367 12456 12457 12467 12567 13456 13457 13467 13567 14567 23456 23457 23467 23567 24567 34567