: This article mainly introduces the php bubble sorting method. if you are interested in the PHP Tutorial, refer to it. $ Arr = array (421,226,588 );
$ N = count ($ arr);/* count () function calculates the number of units in the array or the number of attributes in the object. For an array, return the number of its elements. for other values, return 1. If the parameter is a variable but the variable is not defined, 0 is returned. If the mode is set to COUNT_RECURSIVE (or 1), the number of elements in the array in the multi-dimensional array is calculated recursively */
// Echo $ n;
For ($ h = 0; $ h <$ n-1; $ h ++) {// Outer Loop n-1
For ($ I = 0; $ I <$ n-$ H-1; $ I ++ ){
If ($ arr [$ I]> $ arr [$ I + 1]) {// you can determine the array size and reverse the position.
$ K/p> $ Arr [$ I + 1] = $ arr [$ I];
$ Arr [$ I] = $ kong;
}
}
}
Var_dump ($ arr );
?>
Result:
Array (19) {[0] => int (2) [1] => int (4) [2] => int (5) [3] => int (9) [4] => int (10) [5] => int (11) [6] => int (16) [7] => int (21) [8] => int (23) [9] => int (26) [10] => int (39) [11] => int (44) [12] => int (55) [13] => int (55) [14] => int (85) [15] => int (88) [16] => int (226) [17] => int (421) [18] => int (588 )}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above introduces the php bubble sorting method, including some content, and hope to be helpful to friends who are interested in PHP tutorials.