点击(此处)折叠或打开
-
<?php
-
-
define( "N" ,3);
-
$arr = array( 'a','b','c','d','e','f','g','h','i','j');
-
-
$out = g( N );
-
var_dump( $out );
-
-
function g( $n = 4, $o = '' ){
-
global $arr;
-
-
$temp = array();
-
for( $i=0; $i<$n; $i++ ){
-
-
if( $i == 0 ) {
-
$temp = j($o);
-
continue;
-
}
-
-
$temp2 = array();
-
foreach( $temp as $k=>$v ){
-
//由于j返回的是一个数组,如果直接用$temp3[]=j($v),则$temp3成了二维数组
-
$temp2 = array_merge( $temp2, j( $v ));
-
}
-
$temp = $temp2;
-
}
-
-
return $temp;
-
}
-
-
function a( $o ){
-
global $arr;
-
-
$arr_temp = array();
-
for( $j=0; $j<N; $j++){
-
$arr_temp[ $j ] = $o.$arr[ $j ];
-
}
-
-
return $arr_temp;
-
}
-
-
function j( $o ){
-
global $arr;
-
-
$arr_temp = array();
-
for( $j=0; $j<N; $j++){
-
if( strpos( $o, $arr[ $j ] ) === false ) $arr_temp[ $j ] = $o.$arr[ $j ];
-
}
-
-
return $arr_temp;
-
}
-
-
-
- ?>