The combination of multiple arrays is discussed. suppose there are three arrays (not sure how many arrays actually exist): $ arr1 & nbsp ;=& nbsp; array (1, & nbsp; 2, & nbsp; 3, & nbsp; 4); $ arr2 & nbsp; = & nbsp; array (10, & nbsp; 20, & nbsp; 30, combining multiple arrays
Suppose there are three arrays (actually not sure how many arrays ):
$ Arr1 = array (1, 2, 3, 4 );
$ Arr2 = array (10, 20, 30, 40 );
$ Arr3 = array (100,200,300,400 );
Result to be implemented:
Array (
Array (100 ),
Array (200 ),
Array (300 ),
Array (400 ),
Array (100 ),
Array (200 ),
Array (300 ),
Array (400 ),
Array (1, 30, 100 ),
...
);
You don't want to use recursion, but you can also look at the arrangement and combination to share it:
------ Solution --------------------
Can array () be simplified to [] php5.4? How can I remember php5.3?
Simple comments:
$ D = func_get_args (); // read the input parameters to the array (php4)
If (count ($ d) <2) return current ($ d );
$ N = array_product (array_map ('count', $ d); // array_product calculates the product of the array value (php5). array_map returns the array (php4) processed by the callback function)
Array_walk ($ d, function (& $ v, $ k, $ n) {// use the callback function to process the closure of array elements (php3) (php5.3)
$ V = array_chunk (call_user_func_array ('Array _ merge', array_pad ([$ v], $ n/count ($ v), $ v), 1 );
}, $ N); // array_chunk cut array (php4)
// Call_user_func_array it is useful to call a specified function and pass the parameter array (php4) to execute a variable number of functions.
Foreach ($ d as $ I =>$ t ){
If ($ I = 0 ){
$ R = $ t;
} Else {
Array_multisort (array_map (function ($ v) {return $ v [0] ;}, $ r), $ r );
$ R = array_map ('Array _ merge', $ r, $ t );
}
}
------ Solution --------------------
function my_arr_combine()
{
$args = func_get_args();
$final = array_shift($args);
while($f = array_shift($args))
{
$r = array();