sorting array in predefined order - uksort
| From: | olinux | Date: | Fri, 24 May 2002 14:59:17 +0000 |
| Subject: | sorting array in predefined order - uksort | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-99089@lists.php.net to get a copy of this message | ||
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