//$words = array(‘china’,’mother’,’father’,’hello’,’welcome’);
//排列组合
$words = array(‘a’, ‘b’, ‘c’, ‘d’, ‘e’);
$res = array();
getCombines($words, 5);
print_r($res);
function getCombines($arr, $len=0, $str=””) {
global $res;
$arr_len = count($arr);
if($len == 0){
$res[] = $str;
}else{
for($i=0; $i<$arr_len; $i++){
$tmp = array_shift($arr);
if (empty($str))
{
getCombines($arr, $len-1, $tmp);
}
else
{
getCombines($arr, $len-1, $str.”,”.$tmp);
}
array_push($arr, $tmp);
}
}
}