Discussion on multiple array progression combinations

Source: Internet
Author: User
Group discussions on multiple arrays
Let's say there are three arrays (actually indeterminate number of groups):
$arr 1 = Array (1, 2, 3, 4);
$arr 2 = Array (10, 20, 30, 40);
$arr 3 = Array (100, 200, 300, 400);

To achieve the result:
Array
Array (1,10,100),
Array (1,10,200),
Array (1,10,300),
Array (1,10,400),
Array (1,20,100),
Array (1,20,200),
Array (1,20,300),
Array (1,20,400),
Array (1,30,100),
...
);
Do not want to use recursion, but can also be implemented to see permutation combinations

Share to:


------Solution--------------------
Can the array () be simplified to [] is php5.4? How do I remember php5.3?

Simply comment:
  $d = Func_get_args ();//reads the passed-in parameter into the array (PHP4)
if (count ($d) < 2) return current ($d);
$n = array_product (Array_map (' count ', $d)); Array_product computes 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 callback function to handle array element (PHP3) closure notation (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 calling a specified function and passing a parameter array (PHP4) is useful for functions that perform a variable number of arguments
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.