usort 使用(转载)

private function arrCmp($a,$b){
 if($a['day_time'] == $b['day_time']){
  return 0;
 }
 return($a['day_time']<$b['day_time']) ? -1 : 1;
}
使用方法:
usort($new, array("DeveloperController", "arrCmp"));

数组原型:
Array (
  [0] => Array ( [day_time] => 1291161600 [one_sum_click_num] => 2 [two_sum_click_num] => 2 )
  [1] => Array ( [day_time] => 1291248000 [one_sum_click_num] => 7 [two_sum_click_num] => 5 )
  [2] => Array ( [day_time] => 1291334400 [one_sum_click_num] => 4 )
  [3] => Array ( [day_time] => 1291593600 [two_sum_click_num] => 2 ) ) )
  这样子根据其数组中的 day_time字段进行排序。

posted @ 2014-09-22 11:44  jamesbd  阅读(176)  评论(0编辑  收藏  举报