The example of this article describes the method of PHP to find all array of arrays, all combinations of elements. Share to everyone for your reference, specific as follows:
<?php
$source = Array (' PLL ', ' I ', ' love ', ' You ', ' Hey ');
Sort ($source); Ensure that the initial array is ordered
$last = count ($source)-1;//$source tail element subscript
$x = $last;
$count = 1; Number of combinations the
echo implode (', ', $source), "<br>";//output The first combination while
(true) {
$y = $x-;//Adjacent two elements
if ($ source[$x] < $source [$y]) {//If the value of the previous element is less than the value of the latter element
$z = $last;
while ($source [$x] > $source [$z]) {//start from the tail, find the first value greater than the $x element
$z-;
}
/* Exchange $x and $z the value of the element/
list ($source [$x], $source [$z]) = Array ($source [$z], $source [$x]);
/* The elements after the $y are all in reverse order
($i = $last; $i > $y; $i--, $y + +) {
list ($source [$i], $source [$y]) = Array ($source [$y], $source [$i]);
}
echo implode (', ', $source), "<br>"; Output combination
$x = $last;
$count + +;
}
if ($x = = 0) {//all combinations complete break
;
}
}
Echo ' total: ', $count, "\ n";
? >
For more information on PHP related content readers can view the site topics: "PHP array" Operation Techniques Encyclopedia, "PHP Mathematical Calculation Skills Summary", "PHP Regular Expression Usage Summary", "Php+ajax Tips and Application Summary", "PHP operation and operator Usage Summary", " PHP Network Programming Skills Summary, "Introduction to PHP Basic Grammar", "PHP date and Time usage summary", "PHP object-oriented Programming Introductory Course", "PHP string (String) Usage Summary", "Php+mysql database Operation Tutorial" and " A summary of common PHP database operations tips
I hope this article will help you with the PHP program design.