Sorting algorithms-Simple selection and sorting algorithms --
Simply select sorting, that is, execute the n-I comparison, and then select the smallest value from the n-I + 1 data. If the minimum value is not I (1 = <I <= n) and I.
1 <? Php 2 $ arr = array (9, 5 ); 3 4/** 5 * return the array 6 * @ param $ array to be sorted 7 * return array into sorted array 8 */9 function SelectSort ($ array) {10 11 for ($ I = 0; $ I <count ($ array); $ I ++) {12 13 $ min = $ I; // set the current subscript to the minimum subscript 14 for ($ j = $ I; $ j <count ($ array); $ j ++) {// After n-I keyword comparison 15 16 if ($ array [$ min]> $ array [$ j]) {17 $ min = $ j; // if the subsequent value is smaller than the current value, the subsequent value Key is assigned to $ min; 18} 19} 20 21 if ($ min! = $ I) {// determines whether the value of $ min is changed. If yes, 22 23 $ temp = $ array [$ min] is exchanged. 24 $ array [$ min] = $ array [$ I]; 25 $ array [$ I] = $ temp; 26} 27} 28 return $ array; 29} 30 31 $ result = SelectSort ($ arr); 32 echo '<pre>'; 33 print_r ($ result); 34?>