Php array bubble sorting algorithm instance and php array algorithm instance. Php array bubble sorting algorithm example, php array algorithm example this article describes the php array bubble sorting algorithm. For your reference, see php * @ bubble sorting algorithm php array bubble sorting algorithm instance and php array algorithm instance.
This article describes the php array bubble sorting algorithm. We will share this with you for your reference. The details are as follows:
<? Php/* @ bubble sorting algorithm */$ array = array (,); $ len = count ($ array ); // calculate the array length for ($ I = 0; $ I <$ len-1; $ I ++) {// you need to compare $ len-1 wheel, each round needs to compare $ len-1 times for ($ j = 0; $ j <$ len-1; $ j ++) {// needs to compare $ len-1 times, because no number can be compared after the loop to the last number, the number of loops to the second to the last is exactly $ k = $ j + 1; // Obtain the subscript of the next number of the current number, we compare the if ($ array [$ j]> $ array [$ k]) values with the subscript 0---4, respectively. {// compare two numbers. if the previous number is greater than the last one, the order of the two numbers is exchanged. $ t = $ array [$ j]; $ array [$ j] = $ array [$ k]; $ array [$ k] = $ t;} // after the first loop comparison, perform the next round of comparison. } Print_r ($ array);/* the key to understanding the bubble sorting is that its comparison result is to put a large number in the future, and the largest and second largest number is obtained in sequence, the third largest number... And so on */?>