This article mainly introduces the php array bubble sorting algorithm and analyzes the implementation principle and related skills of the php array bubble sorting algorithm in the form of a simple example, for more information, see the example in this article. 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 */?>