400字范文,内容丰富有趣,生活中的好帮手!
400字范文 > php 重新组合数组_PHP数组组合

php 重新组合数组_PHP数组组合

时间:2020-11-18 18:22:59

相关推荐

php 重新组合数组_PHP数组组合

慕神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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。