multidimensional array sorting
| From: | Kelly Protsko | Date: | Sat, 19 Apr 2003 16:27:32 +0000 |
| Subject: | multidimensional array sorting | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-144487@lists.php.net to get a copy of this message | ||
I have a text file which I read into an 2-D array so each row holds the
date in its pieces and the event title. I want to sort this array based
on the day of the month in ascending order.
The array is setup like this:
January,7,2003,event title
January,1,2003,event title
January,4,2003,event title
$list[0][0] = "January";
$list[0][1] = 3;
$list[0][2] = 2003;
$list[0][3] = "event title";
This is the way I was trying to sort the array but the order doesn't
seem to change.
usort($lines,compare);
function compare($x,$y)
{
If ($x[1] == $y[1])
return 0;
else If ($x[1] < $y[1])
return -1;
else
return 1;
}
Kelly