PHP array of all permutations, elements of all combinations of methods, PHP arrays
In this paper, we describe the method of all the combinations of elements in the PHP array. Share to everyone for your reference, 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; Combined number of statistics echo implode (', ', $source), "
"; Output the first combination while (true) { $y = $x--;//two elements adjacent if ($source [$x] < $source [$y]) {//If the value of the previous element is less than the value of the next element $z = $la St; while ($source [$x] > $source [$z]) {//start at the tail, find the first value greater than $x element $z--; } /* Swap values for $x and $z elements */ list ($source [$x], $source [$z]) = Array ($source [$z], $source [$x]); /* The elements after the $y are all reversed * /for ($i = $last; $i > $y; $i--, $y + +) { list ($source [$i], $source [$y]) = Array ($source [ $y], $source [$i]); } echo implode (', ', $source), "
"; Output combination $x = $last; $count + +; } if ($x = = 0) {//all combinations complete break ; }} Echo ' total: ', $count, ' \ n ';? >
More about PHP related content readers can view the topic: "PHP array" operation Skills Daquan, "PHP Math Skills Summary", "PHP Regular Expression Usage Summary", "Php+ajax Tips and Applications Summary", "PHP operation and operator Usage Summary", " PHP Network Programming Skills Summary, PHP Basic Grammar Introductory tutorial, PHP date and Time usage summary, PHP Object-oriented Programming primer tutorial, PHP string Usage Summary, PHP+MYSQL Database Operations primer, and A summary of common PHP database operation techniques
I hope this article is helpful to you in PHP programming.
http://www.bkjia.com/PHPjc/1123806.html www.bkjia.com true http://www.bkjia.com/PHPjc/1123806.html techarticle php array of all permutations, elements of all combinations of methods, PHP arrays in this article describes the PHP array of all permutations, elements of all combinations of methods. Share to everyone for your reference, as follows: ...