<BR><?php <BR>/** <BR>* Sort an two-dimension array by some level two items use array_multisort() function. <BR>* <BR>* sysSortArray($Array,"Key1","SORT_ASC","SORT_RETULAR","Key2"……) <BR>* @author Chunsheng Wang <BR>* @param array $ArrayData the array to sort. <BR>* @param string $KeyName1 the first item to sort by. <BR>* @param string $SortOrder1 the order to sort by("SORT_ASC"|"SORT_DESC") <BR>* @param string $SortType1 the sort type("SORT_REGULAR"|"SORT_NUMERIC"|"SORT_STRING") <BR>* @return array sorted array. <BR>*/ <BR>function sysSortArray($ArrayData,$KeyName1,$SortOrder1 = "SORT_ASC",$SortType1 = "SORT_REGULAR") <BR>{ <BR>if(!is_array($ArrayData)) <BR>{ <BR>return $ArrayData; <BR>} <BR>$ArgCount = func_num_args(); <BR>for($I = 1;$I < $ArgCount;$I ++) <BR>{ <BR>$Arg = func_get_arg($I); <BR>if(!eregi("SORT",$Arg)) <BR>{ <BR>$KeyNameList[] = $Arg; <BR>$SortRule[] = '<i>·本2文来源gaodai$ma#com搞$代*码网2</i><strong>搞gaodaima代码</strong>$'.$Arg; <BR>} <BR>else <BR>{ <BR>$SortRule[] = $Arg; <BR>} <BR>} <BR>foreach($ArrayData AS $Key => $Info) <BR>{ <BR>foreach($KeyNameList AS $KeyName) <BR>{ <BR>${$KeyName}[$Key] = $Info[$KeyName]; <BR>} <BR>} <BR>$EvalString = 'array_multisort('.join(",",$SortRule).',$ArrayData);'; <BR>eval ($EvalString); <BR>return $ArrayData; <BR>} <BR>//################# 示例 ################# <BR>$arr = array( <BR>array( <BR>'name' => '学习', <BR>'size' => '1235', <BR>'type' => 'jpe', <BR>'time' => '1921-11-13', <BR>'class' => 'D', <BR>), <BR>array( <BR>'name' => '中国功夫', <BR>'size' => '153', <BR>'type' => 'jpe', <BR>'time' => '2005-11-13', <BR>'class' => 'J', <BR>), <BR>array( <BR>'name' => '编程', <BR>'size' => '35', <BR>'type' => 'gif', <BR>'time' => '1997-11-13', <BR>'class' => 'A', <BR>), <BR>array( <BR>'name' => '中国功夫', <BR>'size' => '65', <BR>'type' => 'jpe', <BR>'time' => '1925-02-13', <BR>'class' => 'D', <BR>), <BR>array( <BR>'name' => '中国功夫', <BR>'size' => '5', <BR>'type' => 'icon', <BR>'time' => '1967-12-13', <BR>'class' => 'C', <BR>), <BR>); <BR>print_r($arr); <BR>//注意:按照数字方式排序时 153 比 65 小 <BR>$temp = sysSortArray($arr,"class","SORT_ASC","type","SORT_DESC","size","SORT_ASC","SORT_STRING"); <BR>echo "<pre class="prettyprint linenums">"; <BR>print_r($temp); <BR>?> <BR>