-3

I'm making a website for a music promotion company. For each artist I have a seperate array containing event information, like this:

<?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",
    );


?>

I want to combine all of these separate arrays, using includes, in to one events page and have them ordered chronologically. Is there a way to do this with the "date" associative array?

So it would end up like this: March 18th 2013 Don Ross The Half Moon, Putney

March 20th 2013 Brooke Miller Hobos, Bridgend

March 29th 2013 Jimmy Wahlsteen The Garage, Swansea

1 Answers1

1

yup, you would need to use the uasort function like so:

$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;
});
DiverseAndRemote.com
  • 19,314
  • 10
  • 61
  • 70
  • Thanks very much mate. I'm new to all this and I have no idea where to start looking for these specific functions. – user2059458 Feb 13 '13 at 18:35