PHP array content does not combine the Arrangement Algorithm repeatedly, and php array Arrangement Algorithm
/* Param: $ arrs two-dimensional array
GetArrSet (array (),...))
Arrays do not repeat the set
*/
Function getArrSet ($ arrs, $ _ current_index =-1)
{
// Total group
Static $ _ total_arr;
// Total number of subscripts
Static $ _ total_arr_index;
// Input array Length
Static $ _ total_count;
// Concatenate an array temporarily
Static $ _ temp_arr;
// Enter the first layer of the input array, clear the static array, and initialize the length of the input Array
If ($ _ current_index <0)
{
$ _ Total_arr = array ();
$ _ Total_arr_index = 0;
$ _ Temp_arr = array ();
$ _ Total_count = count ($ arrs)-1;
GetArrSet ($ arrs, 0 );
}
Else
{
// Number of layers in the loop $ _ current_index
Foreach ($ arrs [$ _ current_index] as $ v)
{
// If the current loop array is less than the input array Length
If ($ _ current_index <$ _ total_count)
{
// Add the value of the current array to the temporary Array
$ _ Temp_arr [$ _ current_index] = $ v;
// Continue to loop the next Array
GetArrSet ($ arrs, $ _ current_index + 1 );
}
// If the current loop array is equal to the input array length (this array is the final array)
Else if ($ _ current_index === _ total_count)
{
// Add the value of the current array to the temporary Array
$ _ Temp_arr [$ _ current_index] = $ v;
// Add the temporary array to the total number Group
$ _ Total_arr [$ _ total_arr_index] = $ _ temp_arr;
// Total number of subscripts + 1
$ _ Total_arr_index ++;
}
}
}
Return $ _ total_arr;
}
/************* TEST **************/
$ Arr = array (
Array ('red', 'White '),
Array ('red', 'Blue ', 'black '),
Array ('brown ', 'Gray', 'purple '),
Array ('green', 'cyan ', 'baby Blue ')
);
Echo "<pre> ";
Print_r (getArrSet ($ arr ));
Function zuhe ($ arr ){
If (count ($ arr)> = 2 ){
$ Tmparr = array ();
$ Arr1 = array_shift ($ arr );
$ Arr2 = array_shift ($ arr );
Foreach ($ arr1 as $ k1 => $ v1 ){
Foreach ($ arr2 as $ k2 => $ v2 ){
$ Tmparr [] = $ v1. $ v2;
}}
Array_unshift ($ arr, $ tmparr );
$ Arr = zuhe ($ arr );
} Else {
Return $ arr;
}
Return $ arr;
}
$ Arr = array (
Array (1, 2 ),
Array ('A', 'B '),
Array ('C', 'D ')
);
Print_r (zuhe ($ arr); exit;
Reference from https://www.cnblogs.com/GaZeon/p/5602049.html