经测试代码如下:
/**
* 数组组合算法
*
* @param
* @author 编程之家 jb51.cc jb51.cc
**/
function combination(){
$array = array();
$arguments = func_get_args();
foreach($arguments as $argument){
if(is_array($argument) === true){
$array[] = $argument;
}else{
$array[] = array($argument);
}
}
$size = count($array);
if($size === 0){
return array();
}else if($size === 1){
return is_array($array[0]) === true ? $array[0] : array();
}else{
$result = array();
$a = $array[0];
array_shift($array);
if(is_array($array) === false){
return $result;
}
foreach($a as $val){
$b = call_user_func_array("combination",$array);
foreach($b as $c){
if(is_array($c) === true){
$result[] = array_merge(array($val),$c);
}else{
$result[] = array($val,$c);
}
}
}
return $result;
}
}
print_r(combination(array("A1","A2"),array("B1","B2"),"1",array("C1","C2","C3")));
/*** 代码来自编程之家 jb51.cc(jb51.cc) ***/
原文链接:https://www.f2er.com/php/529068.html