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), "<br>"; // 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], $ so Urce [$ 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), "<br>"; // Output Combination $ x = $ last; $ count ++ ;} if ($ x = 0) {// break is fully combined;} echo 'total: ', $ count, "\ n";?>