logo       

sorting array in predefined order - uksort: msg#03633

php.general

Subject: sorting array in predefined order - uksort

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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise