<?php // 冒泡(起泡)排序法 $arr = array (0,1,2,3,4,5,6,7,8,9); $count = count ( $arr ); for ( $i =0; $i < $count ; $i ++ ){ for ( $j =0; $j < $count - $i -1; $j ++){ if ( $arr [ $j ] < $arr [ $j +1]){ $tmp = $arr [ $j ]; $arr [ $j ]= $arr [ $j +1]; $arr [ $j +1]= $tmp ; } } } print_r( $arr ); |