分类: 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";
Share