PHP selects the sorting algorithm's classic interview questions & lt ;? Php $ unsortedarray (); for ($ i0; $ I & lt; 10; $ I ++) {$ unsorted [] rand ();} printUnsortedArray. & lt; br & gt; printimplode (, $ u PHP select sorting algorithm classic interview questions
"; Print implode (',', $ unsorted); print"
"; Print" Sorted Array.
"; $ Sort = select_sort ($ unsorted); print implode (',', $ sort);/** selection sort1. find the minimum number of arrays 2. exchange with the first number 3. repeat the remaining elements */function select_sort ($ arr = array () {$ min = false; $ n = count ($ arr); for ($ I = 0; $ I <$ n; $ I ++) {$ min = $ I; for ($ j = $ I + 1; $ j <$ n; $ j ++) {if ($ arr [$ j] <$ arr [$ min]) {$ min = $ j ;}// $ tmp = $ arr [$ min]; // $ arr [$ min] = $ arr [$ I]; // $ arr [$ I] = $ tmp; list ($ arr [$ min], $ arr [$ I]) = array ($ arr [$ I], $ arr [$ min]);} return $ arr ;}
?