2010-07-19 63 views
0

如何通过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] => 
         ) 
+0

这是一个在关联数组中的关联数组中的索引数组,我认为您正在寻找对索引数组进行排序。 – BoltClock 2010-07-19 01:38:04

+0

我需要他们排序,以便ssup按字母顺序 – 2010-07-19 01:39:28

回答

5

使用usort并提供自己的函数来进行排序,例如,

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

usort($array, "cmp"); 
+0

非常感谢你,只是把大于一个小于asc和一切都很好 – 2010-07-19 01:48:15