php实用函数整理

1. 排序:array_multisort  可以对多位数组的多个字段进行排序
例子1如下:
//自定义数组排序--按转发数从高到低排序 
 function sortSelfRc($oneLayer){   
      $myselfSort = array(); //自定义排序数组 
       $i=0; 
      foreach($oneLayer as $k=>$layer){ 
       $oneLayer[$i] = $layer; 
       unset($oneLayer[$k]); 
       $myselfSort[] = $layer['reposts_count']; 
     $i++; 
    }    
    array_multisort($myselfSort,SORT_DESC,SORT_NUMERIC,$oneLayer);   
    return $oneLayer; 
 }  


例子2:
.......
 	$list[] = $tmpArr; //要排序的数据源 
 } 
    //用户自定义排序 
    //按客服  在线->离线排序 
    $tmp_arr = array(); 
    foreach ($list as $key => $val) { 
        $tmp_arr[$key] = $val['onlineStatus']; 
    } 
    //按服务客服数量多少排序 
    $tmp_arr2 = array(); 
    foreach ($list as $key => $val) { 
        $tmp_arr2[$key] = $val['session_num']; 
    } 
    array_multisort($tmp_arr, SORT_ASC, $tmp_arr2, SORT_DESC, $list); 


例子3
	foreach($frequencyArray as $key => $value) {
		$frequencyList[$key] = $value['frequency'];
		$valueList[$key] = $value['value'];
	}
	array_multisort($frequencyList, SORT_DESC, $valueList, SORT_ASC, SORT_NUMERIC, $frequencyArray);

 

 

posted on 2013-11-08 10:20  andydaopeng  阅读(164)  评论(0编辑  收藏  举报

导航