数组
/**
*描述:把$input_arr进行组合操作,并返回一个包含所有组合的数组
*参数:$input_arr 操作对象,$delimit 组合的分割符号,$n 每个组合的数组单元数
*作者:surfchen@gmail.com
*版权:任意复制,修改所有内容.
**/
function getSingleComb($input_arr,$delimit,$n)
{
if ($n==1)
{
return $input_arr;
}
$c_num=getCNum($n,count($input_arr));
$new_arr=array();
while (1)
{
$r_arr=array_rand($input_arr,$n);
asort($r_arr);
foreach ($r_arr as $value)
{
$tmp_str[]=$input_arr[$value];
}
$new_str=implode($delimit,$tmp_str);
unset($tmp_str);
if (!in_array($new_str,$new_arr))
{
$new_arr[]=$new_str;
}
if (count($new_arr)>=$c_num)
{
break;
}
}
return $new_arr;
}
/**
*描述:获得组合(请参阅初等数学的排列与组合)个数
*参数:$m 组合的单元数,$n 单元总数
*作者:surfchen@gmail.com
*版权:任意复制,修改所有内容.
**/
function getCNum($m,$n)
{
$store_m=$m;
$store_n=$n;
$dividend=1;
for ($m;$m>1;$m--)
{
$dividend*=$m;
}
$divisor=1;
for ($n;$n>=($store_n-$store_m+1);$n--)
{
$divisor*=$n;
}
return $divisor/$dividend;
}
/**
*描述:把$input_arr进行组合操作,并返回一个包含所有组合的数组
*参数:$input_arr 操作对象,$delimit 组合的分割符号,$n_arr 为一个数组,其值范围必须在从1到count($input_arr)之间
*作者:surfchen@gmail.com
*版权:任意复制,修改所有内容.
**/
function getMultiComb($input_arr,$delimit,$n_arr)
{
$return_arr=array();
foreach ($n_arr as $value)
{
$return_arr=array_merge($return_arr,getSingleComb($input_arr,$delimit,$value));
}
return $return_arr;
}
$input_arr=explode(" ",'sina sohu yahoo baidu 163');
print_r(getMultiComb($input_arr," ",array(1,2,3,4)));
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
