The composition permutation algorithm of PHP array content without repetition

Source: Internet
Author: User
Tags array length repetition

function Getarrset ($arrs, $_current_index=-1)
{
Total Group
Static $_total_arr;
Total group Subscript Count
Static $_total_arr_index;
The input array length
Static $_total_count;
Temporary Patchwork array
Static $_temp_arr;

Enter the first layer of the input array, empty the static array, and initialize the input array length
if ($_current_index<0)
{
$_total_arr=array ();
$_total_arr_index=0;
$_temp_arr=array ();
$_total_count=count ($arrs)-1;
Getarrset ($arrs, 0);
}
Else
{
Looping the $_current_index layer array
foreach ($arrs [$_current_index] as $v)
{
If the array of the current loop is less than the input array length
if ($_current_index<$_total_count)
{
Puts the value of the current array loop out into a temporary array
$_temp_arr[$_current_index]= $v;
Continue looping the next array
Getarrset ($arrs, $_current_index+1);

}
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;
Total group subscript Count +1
$_total_arr_index++;
}

}
}

return $_total_arr;
}

$arr =array (
Array (' 1 '),
Array (' A ', ' B ', ' C '),
Array (' C ', ' B ', ' a '),
Array (' + ', '-', ' * ')
);
Print_r (Getarrset ($arr));

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.