Introduction: This is a detailed page of the Two-dimensional array sorting method in PHP. It introduces PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 344027 'rolling = 'no'> the two-dimensional array sorted by letters in PHP,
In the actual development is still very useful, there is a need to take, http://lab.wehefei.com
<? 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 <wwccss@263.net>
* @ Param array $ arraydata the array to sort.
* @ Param string $ keyname1 the first item to sort.
* @ 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 <$ argcount; $ I ++)
{
$ Arg = func_get_arg ($ I );
If (! Eregi ("sort", $ Arg ))
{
$ Keynamelist [] = $ ARG;
$ Sortrule [] = '$'. $ ARG;
}
Else
{
$ Sortrule [] = $ ARG;
}
}
Foreach ($ arraydata as $ key => $ info)
{
Foreach ($ keynamelist as $ keyname)
{
$ {$ Keyname} [$ key] = $ info [$ keyname];
}
}
$ Evalstring = 'array _ multisort ('. Join (",", $ sortrule).', $ arraydata );';
Eval ($ evalstring );
Return $ arraydata;
}
#################
$ Arr = array (
Array (
'Name' => 'learn ',
'SIZE' => '123 ',
'Type' => 'jpe ',
'Time' => '2017-11-13 ',
'Class' => 'D ',
),
Array (
'Name' => 'Kung Fu China ',
'SIZE' => '123 ',
'Type' => 'jpe ',
'Time' => '2017-11-13 ',
'Class' => 'J ',
),
Array (
'Name' => 'programmatically ',
'SIZE' => '35 ',
'Type' => 'gif ',
'Time' => '2017-11-13 ',
'Class' => 'A ',
),
Array (
'Name' => 'Kung Fu China ',
'SIZE' => '65 ',
'Type' => 'jpe ',
'Time' => '2017-02-13 ',
'Class' => 'D ',
),
Array (
'Name' => 'Kung Fu China ',
'SIZE' => '5 ',
'Type' => 'icon ',
'Time' => '2017-12-13 ',
'Class' => 'C ',
),
);
Print_r ($ ARR );
// Note: When sorting by number, 153 is smaller than 65.
$ Temp = syssortarray ($ arr, "class", "sort_asc", "type", "sort_desc", "size", "sort_asc", "sort_string ");
Echo "<PRE> ";
Print_r ($ temp );
?>
Source:
Http://lab.wehefei.com/posts/372
Source: Hefei network product center http://lab.wehefei.com more welcome to pay attention to the next.
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/344027.html pageno: 5.