PHP array of all permutations, elements of all combinations of methods, PHP arrays _php Tutorial

Source: Internet
Author: User
Tags php database php regular expression

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: ...

  • 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.