php中有没有一种方法可以按日期对数组进行排序并显示它们?类似于 asort 或 usort?
问题是日期字段也可以包含“未知”之类的值。我想按日期降序打印所有记录,最后打印 UNKNOWNS。到目前为止,这是我的代码。
foreach ($MailPieceArr as $key => $val) {
$count++;
if (($count % 2) == 1) {
print "<tr bgcolor='#CCCCCC'>";
} else {
print "<tr bgcolor=white>";
}
print "<td align=center>".$MailPieceArr[$key]["type"]."</td>";
print "<td align=center>".$MailPieceArr[$key]["id"]."</td>";
print "<td align=center>".$MailPieceArr[$key]["ddate"]."</td>";
print "<td align=center>".$MailPieceArr[$key]["acode"]."</td>";
print "</tr>";
}
这是我的数组的样子:
print_r($MailPieceArr);
输出:
Array
(
[0] => Array
(
[type] => First-Class
[id] => 77770056
[ddate] => 11/26/2012
[acode] => 2643
)
[1] => Array
(
[type] => First-Class
[id] => 77770057
[ddate] => 11/26/2012
[acode] => 2643
)
[2] => Array
(
[type] => First-Class
[id] => 77770058
[ddate] => 11/21/2012
[acode] => 2641
)
[3] => Array
(
[type] => First-Class
[id] => 77770059
[ddate] => 11/21/2012
[acode] => 2641
)
[4] => Array
(
[type] => First-Class
[id] => 77770042
[ddate] => 10/29/2012
[acode] => 2623
)
[5] => Array
(
[type] => First-Class
[id] => 77770041
[ddate] => 10/29/2012
[acode] => 2623
)
[6] => Array
(
[type] => RR
[id] => 88880001
[ddate] => 10/29/2012
[acode] => 2621
)
[7] => Array
(
[type] => First-Class
[id] => 77770043
[ddate] => 10/17/2012
[acode] => 2625
)
[8] => Array
(
[type] => First-Class
[id] => 77770044
[ddate] => 10/17/2012
[acode] => 2625
)
[9] => Array
(
[type] => RR
[id] => 88880005
[ddate] => 10/17/2012
[acode] => 2619
)
[10] => Array
(
[type] => IMB
[id] => 0001101111111111110011111111111
[ddate] => UNKNOWN
[acode] => 2643
)
)