1
我知道可以在日期排序数组上找到许多帖子。我挣扎了几个小时尝试没有成功排序矿(“$ MYARRAY”)(和我在PHP新手,所以请原谅我,如果答案是显而易见的):在日期排序数组
array(9) {
[0]=> array(1) {["13 March 2012"]=> string(32) "Commandes Anticorps et Kits 2012" }
[1]=> array(1) {["4 May 2012"]=> string(23) "Prix de la Chancellerie" }
[2]=> array(1) { ["17 April 2012"]=> string(23) "MàJ antivirus Kapersky" }
[3]=> array(1) { ["14 May 2012"]=> string(24) "Atelier Formation INSERM" }
[4]=> array(1) { ["14 March 2012"]=> string(13) "Webzine AP-HP" }
[5]=> array(1) { ["11 April 2011"]=> string(32) "Nouvelle Charte des Publications" }
[6]=> array(1) { ["23 April 2012"]=> string(28) "BiblioINSERM: Nouveaux Codes" }
[7]=> array(1) { ["7 March 2012"]=> string(39) "Springer : Protocols également en test" }
[8]=> array(1) { ["4 October 2011"]=> string(48) "[info.biblioinserm] Archives des titres Springer" }
}
所以我想排序日期。
当中,我已经找到了各种解决方案,我已经试过了:
function date_compare($a, $b)
{
$t1 = strtotime($a['datetime']);
$t2 = strtotime($b['datetime']);
return $t1 - $t2;
}
,然后调用的函数:
usort($MyArray, 'date_compare');
,但它不工作... :-(
任何帮助将非常感激!
什么不行,它是否返回任何错误,或者它只是不排序? –
你可以改变原来的$ array(9)的结构吗? – Sebas
它只是不排序日期。 – user1401141