The composition permutation algorithm of PHP array content without repetition

Source: Internet
Author: User
Tags repetition

Recently in the Ecshop Inventory module, we set up inventory of multiple attribute combinations for a product, such as:

A phone with different colors, screen size, system and power, to set up a different inventory, if you have to manually select the attribute combination, it will take a lot of unnecessary time. If you have set the property arrangement combination when you open the page, then it would be best to think about it all day and write the following function:

1<?PHP2 3 /*4 Author:gazeon5 date:2016-6-206 Function:getarrset7 Param: $arrs Two-dimensional array8 Getarrset (Array (),...))9 array contents are not repeated in a combined arrangementTen */ One functionGetarrset ($arrs,$_current_index=-1) A { -     //Total Group -     Static $_total_arr=Array(); the     //Total group subscript count -     Static $_total_arr_index=0; -     //the input array length -     Static $_total_count; +     //Temporary Patchwork array -     Static $_temp_arr=Array(); +      A     //Enter the first layer of the input array and initialize the input array length at     if($_current_index<0) -     { -         $_total_count=Count($arrs)-1; -Getset ($arrs, 0); -     } -     Else in     { -         //looping the $_current_index layer array to         foreach($arrs[$_current_index] as $v) +         { -             //if the array of the current loop is less than the input array length the             if($_current_index<$_total_count) *             { $                 //puts the value of the current array loop out into a temporary arrayPanax Notoginseng                 $_temp_arr[$_current_index]=$v; -                 //continue looping the next array theGetset ($arrs,$_current_index+1); +                  A             } the             //if the array of the current loop equals the length of the input array (this is the last array) +             Else if($_current_index==$_total_count) -             { $                 //puts the value of the current array loop out into a temporary array $                 $_temp_arr[$_current_index]=$v; -                 //adding a temporary array to the total group -                 $_total_arr[$_total_arr_index]=$_temp_arr; the                 //Total group subscript count +1 -                 $_total_arr_index++;Wuyi             } the  -         } Wu     } -      About     return $_total_arr; $ } -  - /*************test**************/ - $arr=Array( A     Array(' A ', ' B ', ' C '), +     Array(' A ', ' B ', ' C '), the     Array(' 1 ', ' 2 ', ' 3 '), -     Array(' I ', ' II ', ' III ') $ ); the  the Var_dump(Getarrset ($arr)); the     

The composition permutation algorithm of PHP array content without repetition

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.