PHP multidimensional array PHP custom functions for two-dimensional array sorting function

Source: Internet
Author: User
In this paper, we describe the function of PHP custom function for two-dimensional array sorting. Share to everyone for your reference, as follows:

/** function: Two-dimensional array sorting function, support multi-key name sort * Return: sorted array * Use: Array_msort (array, key name to sort, sort by); * Example: Array_msort ($cflist, "Chapter_orderid", "SORT_ASC"); * Array_msort ($arr, "name", "Sort_asc", "type", "Sort_desc", "size", "Sort_asc", "sort_string"); */function Array_msort ($ArrayData, $KeyName 1, $SortOrder 1 = "Sort_asc", $SortType 1 = "Sort_regular") {if (!is_array ($  Arraydata) {return $ArrayData;  }//Gets the number of parameters.  $ArgCount = Func_num_args ();    Sorted and placed into the Sortrule array for ($i = 1; $i < $ArgCount; $i + +) {$Arg = Func_get_arg ($i);      if (!eregi ("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;}

More about PHP related content readers can view this site topic: "PHP array" operation Skills Daquan, "PHP Sorting algorithm Summary", "PHP common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", " PHP Math Skills Summary, "PHP Regular Expression Usage summary", "PHP Operations and Operator Usage Summary", "PHP string Usage Summary" and "PHP common database Operation Skills Summary"

I hope this article is helpful to you in PHP programming.

The above describes the PHP multidimensional array PHP custom functions to implement the two-dimensional array sorting function, including the contents of the PHP multidimensional array, I hope that the PHP tutorial interested in a friend helpful.

  • 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.