<?php //php algorithm bubble//3, 8, 99, 75, 23, 1, 29, 51, 24, 13, 78.//the first cycle, if there are small elements on the back, that is, bubbling, so the cycle, the smallest 1 bubble to the top of the , that is, the second cycle of $array[10]=1;//, if there are small elements on the back, and bubbling, so that the cycle, the second small 3 bubbles to the penultimate position, that is, $array[9]=3;//... And so on The number of traversal loop array-1 times, according to the order from the big to the minor array,//which can do some optimization, the first bubble needs to bubble to the last element, the second bubble to the penultimate element is OK, that is, COUNT ($array)-2, can also be optimized place here does not do in-depth discussion. function Dump ($arr) {echo ' <pre> ';p rint_r ($arr); Echo ' </pre> ';} $array = Array (3,8,99,75,23,1,29,51,24,13,78);d UMP ($array), for ($i =0; $i <count ($array); $i + +) {for ($j =0 ; $j <count ($array)-$i-1; $j + +) {if ($array [$j]< $array [$j +1]) {$temp = $array [$j]; $array [$j] = $array [$j +1]; $array [$j +1] = $temp;}}} Dump ($array);