亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1622 | 回復: 0
打印 上一主題 下一主題

PHP中二維數組的排序方法 [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2009-04-29 17:01 |只看該作者 |倒序瀏覽
本文介紹的是從 BugFree 摘錄來的二維數組排序函數,可以實現(xiàn)類似 MySQL 的 ORDER BY 效果,當數組不是從數據庫取得時會有特殊應用。
PHP:  // 說明:PHP中二維數組的排序方法 // 整理:http://www.CodeBit.cn  /**  * @package     BugFree  * @version     $Id: FunctionsMain.inc.php,v 1.32 2005/09/24 11:38:37 wwccss Exp $  *  *  * Sort an two-dimension array by some level two items use array_multisort() function.  *  * sysSortArray($Array,"Key1","SORT_ASC","SORT_RETULAR","Key2"……)  * @author                      Chunsheng Wang   * @param  array   $ArrayData   the array to sort.  * @param  string  $KeyName1    the first item to sort by.  * @param  string  $SortOrder1  the order to sort by("SORT_ASC"|"SORT_DESC")  * @param  string  $SortType1   the sort type("SORT_REGULAR"|"SORT_NUMERIC"|"SORT_STRING")  * @return array                sorted array.  */ function sysSortArray($ArrayData,$KeyName1,$SortOrder1 = "SORT_ASC",$SortType1 = "SORT_REGULAR") {     if(!is_array($ArrayData))     {         return $ArrayData;     }      // Get args number.     $ArgCount = func_num_args();      // Get keys to sort by and put them to SortRule array.     for($I = 1;$I $ArgCount;$I ++)     {         $Arg = func_get_arg($I);         if(!eregi("SORT",$Arg))         {             $KeyNameList[] = $Arg;             $SortRule[]    = '$'.$Arg;         }         else         {             $SortRule[]    = $Arg;         }     }      // Get the values according to the keys and put them to array.     foreach($ArrayData AS $Key => $Info)     {         foreach($KeyNameList AS $KeyName)         {             ${$KeyName}[$Key] = $Info[$KeyName];         }     }      // Create the eval string and eval it.     $EvalString = 'array_multisort('.join(",",$SortRule).',$ArrayData);';     eval ($EvalString);     return $ArrayData; }   //################# 示例 ################# $arr = array(     array(         'name'        =>    '學習',         'size'        =>    '1235',         'type'        =>    'jpe',         'time'        =>    '1921-11-13',         'class'        =>    'dd',     ),     array(         'name'        =>    '中國功夫',         'size'        =>    '153',         'type'        =>    'jpe',         'time'        =>    '2005-11-13',         'class'        =>    'jj',     ),     array(         'name'        =>    '編程',         'size'        =>    '35',         'type'        =>    'gif',         'time'        =>    '1997-11-13',         'class'        =>    'dd',     ),     array(         'name'        =>    '中國功夫',         'size'        =>    '65',         'type'        =>    'jpe',         'time'        =>    '1925-02-13',         'class'        =>    'yy',     ),     array(         'name'        =>    '中國功夫',         'size'        =>    '5',         'type'        =>    'icon',         'time'        =>    '1967-12-13',         'class'        =>    'rr',     ), );  print_r($arr);  //注意:按照數字方式排序時 153 比 65 小 $temp = sysSortArray($arr,"name","SORT_ASC","type","SORT_DESC","size","SORT_ASC","SORT_STRING");  print_r($temp);  ?>
               
               
               

本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u/1222/showart_1914431.html
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP