sort a md array by size
Posted: Wed Apr 19, 2006 3:01 pm
ive been trying to sort a multidimensional array so that the internal arrays are in order of their size, biggest first while maintaining their keys
for example
would become
the only way i have manged to do this is by using a second 1D array to act as a reference index, like this
and then sort the values of this array to put them in order
before this i was playing about with a foreach with nested if statements but that just made a mess of the array and didn't work properly...
is there a way I can clean this up and sort the actual array itself so i dont have to use the second array?
thanks
rj
for example
Code: Select all
$matched_users= array (
"21" =>array(1),
"49" =>array(1,4,8,2),
"39" =>array(1, 2, 3, 4, 5, 6),
"11" =>array(),
"3" =>array(2,5)
);Code: Select all
$matched_users= array (
"39" =>array(1, 2, 3, 4, 5, 6),
"49" =>array(1,4,8,2),
"3" =>array(2,5),
"21" =>array(1),
"11" =>array()
);Code: Select all
foreach($matched_users as $key => $value){
$matched_order[$key] = count($value);
}before this i was playing about with a foreach with nested if statements but that just made a mess of the array and didn't work properly...
is there a way I can clean this up and sort the actual array itself so i dont have to use the second array?
thanks
rj