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