PHP outputs the arrangement and combination of multiple elements. Solve the problem: find an array containing N elements and retrieve M elements to form a new array. a total of arrays can be combined and output [php]? Php $ arrarray (a, B, c, d); $ resultarray (); solution: retrieve M elements from an array containing N elements to form a new array, arrays that can be combined and output
[Php]
$ Arr = array ('A', 'B', 'C', 'D ');
$ Result = array ();
$ T = getCombinationToString ($ arr, 4 );
Print_r ($ t );
Function getCombinationToString ($ arr, $ m ){
If ($ m = 1 ){
Return $ arr;
}
$ Result = array ();
$ TmpArr = $ arr;
Unset ($ tmpArr [0]);
For ($ I = 0; $ I $ S = $ arr [$ I];
$ Ret = getCombinationToString (array_values ($ tmpArr), (M-1), $ result );
Foreach ($ ret as $ row ){
$ Result [] = $ s. $ row;
}
}
Return $ result;
}
?>
Why [php]? Php $ arr = array (a, B, c, d); $ result = array ();...