我有以下数据(最终排序),我需要根据
对行进行排序因为元素由.
edumate_3rdparty.20110209.1000.hourly.sql
edumate_3rdparty.20110209.0800.hourly.sql
edumate_3rdparty.20101209.Thursday.daily.sql
moodle_acots.20110130.1600.hourly.sql
moodle_acots.20110105.0800.hourly.sql
moodle_tara.20110316.1200.hourly.sql
moodle_tags.20110222.1000.hourly.sql
moodle_tags.20110208.1801.hourly.sql
moodle_will.20110302.1100.hourly.sql
moodle_wollo.20101031.October.4.weekly.sql
我怎么能在php中做到这一点?
答案 0 :(得分:3)
以下是关于如何对数据集进行排序的示例。
<?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);
?>
我使用Paul的爆炸性想法来测试场景。所以拇指由他决定:)
答案 1 :(得分:2)