RE: [PHP] Sorting a multidimensional array
| From: | Edward Kay | Date: | Thu, 08 Feb 2007 14:39:48 +0000 |
| Subject: | RE: [PHP] Sorting a multidimensional array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-248570@lists.php.net to get a copy of this message | ||
How about this:
http://uk.php.net/manual/en/function.array-multisort.php#53779
Edward
> -----Original Message-----
> From: Dave Goodchild [mailto:buddhamagnet@gmail.com]
> Sent: 08 February 2007 14:30
> To: Roman Neuhauser
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Sorting a multidimensional array
>
>
> Thanks for that - can't do that as all I know in the database is the start
> and end date for each event (so I don't have to create mapping tables and
> perform massive joins), the rest is handle dynamically.
>
> I think I can do it using usort, this seems to work, any comments?
>
> function compare($x, $y) {
>
> if (($x['date'] == $y['date']) &&
> ($x['start_time'] ==
> $y['start_time'])) {
> return 0;
> } else if (($x['date'] == $y['date']) &&
> ($x['start_time'] <
> $y['start_time'])) {
> return -1;
> } else if (($x['date'] == $y['date']) &&
> ($x['start_time'] >
> $y['start_time'])) {
> return 1;
> } else if ($x['date'] < $y['date']) {
> return -1;
> } else {
> return 1;
> }
> }
>
>