Combination of multiple arrays

Source: Internet
Author: User
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();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.