-3

我正在为一家音乐推广公司制作网站。对于每个艺术家,我都有一个包含事件信息的单独数组,如下所示:

<?php

$donevents = array();
$donevents[101] = array(
    "date" => "March 18th 2013",
    "artist" => "Don Ross",
    "venue" => "The Half Moon, Putney",
    "link" => "http://www.halfmoon.co.uk",
    "label" => "donross",
    );
$donevents[102] = array(
    "date" => "March 19th 2013",
    "artist" => "Don Ross",
    "venue" => "The Moon Club, Cardiff",
    "link" => "http://www.themoonclub.net/",
    "label" => "donross",
    );
$donevents[103] = array(
    "date" => "March 21st 2013",
    "artist" => "Don Ross and Brooke Miller",
    "venue" => "Round Midnight, London",
    "link" => "http://www.roundmidnightbar.com",
    "label" => "donross",
    );
$donevents[104] = array(
    "date" => "March 21st 2013",
    "artist" => "Don Ross",
    "venue" => "Masterclass at the Swindon Academy of Music",
    "link" => "http://www.academyofmusic.ac.uk/locations/location.php?id=9",
    "label" => "donross",
    );
$donevents[105] = array(
    "date" => "March 23rd 2013",
    "artist" => "Don Ross",
    "venue" => "Berits & Brown, Airdrie",
    "link" => "http://www.intimate-gigs.com",
    "label" => "donross",
    );
$donevents[106] = array(
    "date" => "March 25th 2013",
    "artist" => "Don Ross",
    "venue" => "Masterclass at The Academy of Music, Gateshead",
    "link" => "http://www.guitarbar.co.uk",
    "label" => "donross",
    );


?>

我想使用包含将所有这些单独的数组组合到一个事件页面中,并按时间顺序排列它们。有没有办法用“日期”关联数组来做到这一点?

所以它最终会是这样的:2013 年 3 月 18 日 Don Ross The Half Moon,Putney

2013 年 3 月 20 日 Brooke Miller Hobos,布里真德

2013 年 3 月 29 日 Jimmy Wahlsteen 车库,斯旺西

4

1 回答 1

1

是的,您需要像这样使用uasort函数:

$sortedEvents = $donevents;
uasort($sortedEvents, function($eventA, $eventB){
    $eventDateA = DateTime::createFromFormat('F dS yyyy', $eventA['date']);
    $eventDateB = DateTime::createFromFormat('F dS yyyy', $eventB['date']);

    return $eventA->getTimestamp() < $eventB->getTimestamp() ? -1 : 1;
});
于 2013-02-13T17:35:19.077 回答