views:

39

answers:

1

How do i sort this array by ssup asc?

 [xml] => Array
        (
            [sale] => Array
                (
                    [0] => Array
                        (
                            [ref] =>  316205
                            [line] =>  3
                            [partno] => MC41SS
                            [cust] => 
                            [date] => 28/ 6/10
                            [value] =>    
                            [balance] =>      
                            [ssup] => CDA
                            [stdesc] => CDA Built in/Freestanding M/Wave Grill/Convection Oven
                            [sdelinfo] => 
                        )

                    [1] => Array
                        (
                            [ref] =>  316657
                            [line] =>  1
                            [partno] => SRS45E48GB
                            [cust] => 
                            [date] =>  7/ 7/10
                            [value] =>     
                            [balance] =>     
                            [ssup] => Bosch
                            [stdesc] => Bosch S/L 4 Prog Express Wash 49db Dishwasher Silver
                            [sdelinfo] => 
                        )

                    [2] => Array
                        (
                            [ref] =>  316791
                            [line] =>  1
                            [partno] => T44T90N0
                            [cust] => 
                            [date] =>  9/ 7/10
                            [value] =>    
                            [balance] =>   
                            [ssup] => Neff
                            [stdesc] => Neff 90cm Front Control Point & Twist Hob St/St
                            [sdelinfo] =>
                        )
+5  A: 

Use usort and supply your own function to do the sorting, e.g.

function cmp($a, $b)
{
    if ($a['ssup'] == $b['ssup']) {
        return 0;
    }
    return ($a['ssup'] > $b['ssup']) ? -1 : 1;
}

usort($array, "cmp");
Sarfraz
thank you very much, just turned the greater than to a less than for asc and all was fine
jim smith