View Single Post
Old 07-15-2008, 01:33 AM   #1 (permalink)
benton
The Contributor
 
Join Date: Apr 2008
Posts: 78
Thanks: 0
benton is on a distinguished road
Default How to sort a multi-array

I have an array like this
PHP Code:
 Array
(
    [
1] => Array
        (
            [
52] => Milk Chocolate
            
[221] => Vanilla Bean
            
[212] => Banana Cream
            
[80] => Chocolate Peanut Butter
        
)


I need to have it sorted on the value. The only examples I can find for doing this are those using multisort but that resets the keys, which won't work in this case. I tried using usort with a callback function like this but it failed.
PHP Code:
function cmp($a$b)
{
    if (
$a == $b) {
        return 
0;
    }
    return (
$a $b) ? -1;
}
foreach (
$myarray as $sub)
 
$myarray[$sub] = usort($subcmp); 
Would someone please point out my mistake or how best to do this?
benton is offline  
Reply With Quote