$i); } for ($i = 1; $i <= 3; $i++) { $total_time = 0; $function = 'sort_' . $i; for ($j = 0; $j < 20; $j++) { shuffle($array); $time_before = microtime(TRUE); uasort($array, $function); $time_after = microtime(TRUE); $total_time += $time_after - $time_before; } print 'Test ' . $i . ': ' . $total_time . '
'; } function sort_1($a, $b) { $a_weight = (is_array($a) && isset($a['#weight'])) ? $a['#weight'] : 0; $b_weight = (is_array($b) && isset($b['#weight'])) ? $b['#weight'] : 0; if ($a_weight == $b_weight) { return 0; } return ($a_weight < $b_weight) ? -1 : 1; } function sort_2($a, $b) { $a_weight = isset($a['#weight']) ? $a['#weight'] : 0; $b_weight = isset($b['#weight']) ? $b['#weight'] : 0; if ($a_weight == $b_weight) { return 0; } return ($a_weight < $b_weight) ? -1 : 1; } function sort_3(array $a, array $b) { $a_weight = isset($a['#weight']) ? $a['#weight'] : 0; $b_weight = isset($b['#weight']) ? $b['#weight'] : 0; if ($a_weight == $b_weight) { return 0; } return ($a_weight < $b_weight) ? -1 : 1; } ?>