Php calculates the array in full arrangement, the method of all combinations of elements, and the php array. Php calculates the full arrangement of arrays and all combinations of elements. This article describes how php calculates the full arrangement of arrays and all combinations of elements. For your reference, the details are as follows: php searches for arrays in full arrangement, all combinations of elements, and php arrays
The example in this article describes the php method for finding all arrays and all combinations of elements. We will share this with you for your reference. The details are as follows:
<? Php $ source = array ('pll ',' I ', 'ay', 'you', 'hi'); sort ($ source ); // ensure that the initial array is ordered $ last = count ($ source)-1; // The subscript of the element at the end of $ source $ x = $ last; $ count = 1; // echo implode (',', $ source ),"
"; // 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";?>