标签:
<?php header("Content-Type:utf-8"); $arr = array( 0 => array( ‘name‘ => ‘国际原油价格‘, ‘url_pinyin‘ => ‘kucun‘, ), 1 => array( ‘name‘ => ‘原油‘, ‘url_pinyin‘ => ‘jiage‘, ), 2 => array( ‘name‘ => ‘原油价格‘, ‘url_pinyin‘ => ‘yuanyoushe‘ ), ); print_r($arr); // // PHP 二维数组排序 // 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(!preg_match("/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; } print_r(sysSortArray($arr,‘name‘));
标签:
原文地址:http://www.cnblogs.com/weishang/p/4963394.html