Sorting by letters of two-dimensional arrays in PHP

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.