[PHP] Sorting a multidimensional array

[PHP] Sorting a multidimensional array

Post by neuhause » Fri, 09 Feb 2007 22:28:49


# XXXX@XXXXX.COM / 2007-02-08 14:08:13 +0000:

Order in the database. SELECT ... ORDER BY.

--
How many Vietnam vets does it take to *** in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://www.yqcomputer.com/
 
 
 

[PHP] Sorting a multidimensional array

Post by buddhamagn » Fri, 09 Feb 2007 23:30:08

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;
}
}

 
 
 

[PHP] Sorting a multidimensional array

Post by znemet » Fri, 09 Feb 2007 23:31:08

array_multisort?

http://www.yqcomputer.com/

hope that helps
Zoltn Nmeth
 
 
 

[PHP] Sorting a multidimensional array

Post by edwar » Fri, 09 Feb 2007 23:39:48

How about this:
http://www.yqcomputer.com/ #53779

Edward