Re: multidimensional array sorting
| From: | Jim Lucas | Date: | Sat, 19 Apr 2003 16:14:06 +0000 |
| Subject: | Re: multidimensional array sorting | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144484@lists.php.net to get a copy of this message | ||
an example of the array would be nice and helpful.
Jim
----- Original Message -----
From: "Kelly Protsko" <linuxbox@wepsoft.com>
To: <php-general@lists.php.net>
Sent: Saturday, April 19, 2003 8:58 AM
Subject: [PHP] multidimensional array sorting
> I am trying to sort a multidimensional array but it doesn't seem to do
> anything. I have an array that stores the dates broken up into
> month,day, year format. And I want to sort the array based on the day.
> This is the way I was trying to do the sort. I am trying to compare
> the second elements in the lines to sort the array. For some reason it
> doesn't change the order of the array at all. Am I missing a step
> here?
>
> 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
>