• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

PHP排序之二维数组的按照字母排序实现代码

PHP admin 12个月前 (06-08) 4次浏览 已收录 0个评论
<?php 
/** 
* 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; 
} 
$ArgCount = func_num_args(); 
for($I = 1;$I  $Info) 
{ 
foreach($KeyNameList AS $KeyName) 
{ 
${$KeyName}[$Key] = $Info[$KeyName]; 
} 
} 
$EvalString = 'array_multisort('.join(",",$SortRule).',$ArrayData);'; 
eval ($EvalString); 
return $ArrayData; 
} 
//################# 示例 ################# 
$arr = array( 
array( 
'name' => '学习', 
'size' => '1235', 
'type' => 'jpe', 
'time' => '1921-11-13', 
'class' => 'D', 
), 
array( 
'name' => '中国功夫', 
'size' => '153', 
'type' => 'jpe', 
'time' => '2005-11-13', 
'class' => 'J', 
), 
array( 
'name' => '编程', 
'size' => '35', 
'type' => 'gif', 
'time' => '1997-11-13', 
'class' => 'A', 
), 
array( 
'name' => '中国功夫', 
'size' => '65', 
'type' => 'jpe', 
'time' => '1925-02-13', 
'class' => 'D', 
), 
array( 
'name' => '中国功夫', 
'size' => '5', 
'type' => 'icon', 
'time' => '1967-12-13', 
'class' => 'C', 
), 
); 
print_r($arr); 
//注意:按照数字方式排序时 153 比 65 小 
$temp = sysSortArray($arr,"class","SORT_ASC","type","SORT_DESC","size","SORT_ASC","SORT_STRING"); 
echo "
"; 
print_r($temp); 
?>

更多PHP排序之二维数组的按照字母排序实现代码相关文章请关注PHP中文网!


39MO , 版权所有丨如未注明 , 均为原创丨转载请注明原文链接:PHP排序之二维数组的按照字母排序实现代码
喜欢 (0)
[1353713598@qq.com]
分享 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址