"Internal sorting Method"
First, Exchange sorting method
1. Bubble Sorting method
<?PHP//Bubble Sort method (small to large) $arr=Array(55,20,10,8,2,0); functionBubblesort (&$arr) { //after the second number is sorted, the first number does not need to repeat the loop again, so the number of cycles < count ($arr)-1 for($i= 0;$i<Count($arr)-1;$i++) { //each element is compared in turn, with two elements comparing size, that is, the number of cycles < count ($arr)-1, followed by a sorted number without the next cyclic sort, that is, COUNT ($arr)-$i-1 for($j= 0;$j<Count($arr)-$i-1;$j++) { if($arr[$j]>$arr[$j+1]) { $temp=$arr[$j]; $arr[$j] =$arr[$j+1]; $arr[$j+1] =$temp; }//Echo ($arr [$j]). " "; }//Print_r ($arr);//echo ' <br/> ';}} bubblesort ($arr); Print_r($arr);?>
2. Quick Sort Method
Ii. Choice of sorting method
Three, inserting type sorting method
1. Insert Sort method
2. Hill Sort method
3. Two binary tree sorting method
"External sorting: Sort by external file"
Note: If the sorting method is encapsulated into a function so that it can be called directly at a later time, use the return value, or the shape to participate in the address character "&", such as:& $arr
PHP array sorting