This article mainly introduces php's method of finding all arrays and all combinations of elements, involving php's techniques for separating arrays and strings, traversing, and mathematical operations, for more information, see the example in this article. We will share this with you for your reference. The details are as follows:
"; // Output the first combination while (true) {$ y = $ x --; // two adjacent elements, if ($ source [$ x] <$ source [$ y]) {// if the value of the previous element is less than the value of the next element $ z = $ last; while ($ source [$ x]> $ source [$ z]) {// starting from the end, find the first value greater than $ x element $ z --;} /* exchange the values of $ x and $ z elements */list ($ source [$ x], $ source [$ z]) = array ($ source [$ z], $ source [$ x]);/* sort all elements after $ y in reverse order */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 are completed break ;}} echo 'total: ', $ count, "\ n";?>
I hope this article will help you with PHP programming.
For more information about php's full array arrangement, please refer to PHP's Chinese network for more articles on the methods of all combinations of elements!