Re: sorting array in predefined order - uksort
| From: | Miguel Cruz | Date: | Fri, 24 May 2002 17:07:23 +0000 |
| Subject: | Re: sorting array in predefined order - uksort | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-99106@lists.php.net to get a copy of this message | ||
Your comparison function doesn't compare anything.
You should look at $a and $b and return an answer indicating which one
comes first. If you want $a to come before $b, return -1. If they're the
same, return 0. If you want $a to come after $b in the sorted list, return
1.
miguel
On Fri, 24 May 2002, olinux wrote:
> I am trying to sort array by key to a defined order -
> I thought uksort would be best option. Here's what i
> have come up with from the manual example - however it
> doesn't work at all.
>
> I want to sort this array by $region
>
> Array looks like this:
> $articles[$region][$article_id][$column_name]
>
> // END ADD ARTICLES TO MULTIDIMENSIONAL ARRAY
>
> // SORT ARRAY BY REGION
> function cmp ($a, $b) {
> if ($a == 'national') return 0;
> elseif ($a == 'international') return 5;
> elseif ($a == 'west') return 1;
> elseif ($a == 'south') return 2;
> elseif ($a == 'east') return 3;
> elseif ($a == 'midwest') return 4;
> }
>
> uksort ($articles, "cmp");
>
> Thanks much,
> olinux
>
>
>
> __________________________________________________
> Do You Yahoo!?
> LAUNCH - Your Yahoo! Music Experience
> http://launch.yahoo.com
>
>