Toc
0 results found
Seven Chen
自定义排序
2013/06/04 PHP专题

[code language=”php”] function microtime_float() { list ( $usec, $sec ) = explode ( “ “, microtime () ); return (( float ) $usec + ( float ) $sec); } function cmp($a, $b) { if ($a == $b) { return 0; } return ($a < $b) ? - 1 : 1; } /** * **** */ $time_start = microtime_float (); $ss = array (); for($j = 0; $j < 3000; ++ $j) { $n = $j + rand ( 0, 999999 ) / 0.000001; array_push ( $ss, $n ); } usort ( $ss, “cmp” ); $tim = microtime_float () - $time_start; print_r ( $ss ); echo “Did nothing in “ . sprintf ( “%.2f”, $tim ) . “ seconds\n”; [/code]

本文作者:Seven Chen
版权声明:本文首发于Seven Chen的博客,转载请注明出处!