PHP two-dimensional array sorting-default natural sort

Source: Internet
Author: User
What is a two-dimensional array? A two-dimensional array is essentially an array of array elements, that is, an array of arrays, a type descriptor array name [constant expression] [constant expression]. A two-dimensional array is also called a matrix, and the matrix with equal number of rows is called Variable square. Symmetric matrix a[i][j] = A[j][i], diagonal matrix: N-step matrices are 0 elements outside the main diagonal. PHP two-dimensional array sorting function, the default natural sort, that is sort. Here you can specify a number of methods to sort by a value in a two-dimensional array, depending on the program note below.

/** * @function two-dimensional array natural sort * @author www.phpernote.com * @param array $array the arrays to be sorted (two Dimension) * @param string key depends on which key to sort * @param string order ordering (SORT_ASC,SORT_DESC) * @param String type sorting method (Sort_regular,sor t_numeric,sort_string) * @return array sorted array. */function Phpsortarray ($array, $key, $order = "Sort_asc", $type = "Sort_regular") {if (!is_array ($array) | |    Empty ($ $array)) {return $array;        } $ArgCount =func_num_args ();//Returns the number of arguments passed to the currently defined function for ($I =1; $I < $ArgCount; $I + +) {$Arg =func_get_arg ($I);            if (!eregi ("SORT", $Arg)) {$KeyNameList []= $Arg;        $SortRule []= ' $ '. $Arg;        }else{$SortRule []= $Arg; }} foreach ($array as $Key = + $Info) {foreach ($KeyNameList as $KeyName) {${$KeyName}[$Key]= $Info [        $KeyName];    }} $EvalString = ' Array_multisort ('. Join (",", $SortRule). ', $array);    eval ($EvalString); return $array;} 

The above is about the PHP two-dimensional array ordering of the default natural ordering of the tutorial, we hope to be 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.