下面是關於如何對數據集進行排序的示例。
<?php
$a=array();
$a[]=explode('.','edumate_3rdparty.20110209.1000.hourly.sql');
$a[]=explode('.','edumate_3rdparty.20110209.0800.hourly.sql');
$a[]=explode('.','edumate_3rdparty.20101209.Thursday.daily.sql');
$a[]=explode('.','moodle_acots.20110130.1600.hourly.sql');
$a[]=explode('.','moodle_acots.20110105.0800.hourly.sql');
$a[]=explode('.','moodle_tara.20110316.1200.hourly.sql');
$a[]=explode('.','moodle_tags.20110222.1000.hourly.sql');
$a[]=explode('.','moodle_tags.20110208.1801.hourly.sql');
$a[]=explode('.','moodle_will.20110302.1100.hourly.sql');
$a[]=explode('.','moodle_wollo.20101031.October.4.weekly.sql');
shuffle($a);
// all you need is this function
function special($a, $b){
if($a[0]!=$b[0])return strcmp($a[0],$b[0]);// asc
if($a[1]!=$b[1])return strcmp($b[1],$a[1]);// desc
return strcmp($b[2],$a[2]);// desc
}
usort($a,'special');
// and maybe the above call
echo'<pre>';
foreach($a as $id=>$value)
$a[$id]=implode('.',$a[$id]);
var_dump($a);
?>
我用保羅的爆炸的想法來得到測試場景。所以大拇指向他:)
那麼......你擔心它會做多快? – Khez 2011-04-05 03:40:40