RE: array sort question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks for the example using array_multisort.  I'd been wondering how I
could use that function to do what I want.  It looks like it's more flexible
in the long run, but I was able to use Paul's recommendation to do what I
want.  Here's the code I ended up using:

function cmp ($a, $b) { 
   return strcmp($a["Title"], $b["Title"]); 
} 

uasort($list, "cmp");

-Ed



> -----Original Message-----
> Sorry for the empty reply (miss slide of the finger on my touch pad).
> You can use array_multisort(); The code would look something like
> this, remember, this is untested code so be warned before any flaming
> is done:
> 
> //CODE
> //You need to restructure your array like this:
> $menu["ID"][1] = 5;
> $menu["Title"][1] = "Test 1";
> $menu["ID"][2] = 3;
> $menu["Title"][2] = "Test 4";
> //Then run array_multisort
> array_multisort($menu['Title'],$menu['ID']);
> 
> //END CODE
> 
> Like this it will sort alphabetically or numerically (which ever
> needed) ascending. You can put tags after the first variable like
> this:
> 
> array_multisort($menu['Title'],SORT_ASC,SORT_STRING,$menu['ID']);
> 
> If there are any more keys in the $menu array you need to list them
> after the $menu['ID'] key so they will be sorted according to the
> $menu['Title'] key. The first key you put into array_multisort() is
> the one that the rest get sorted by.

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux