Home  >  Article  >  Backend Development  >  php-Arrays function-array_multisort-sort multiple arrays or multidimensional arrays_PHP tutorial

php-Arrays function-array_multisort-sort multiple arrays or multidimensional arrays_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:51:11969browse

array_multisort() sorts multiple arrays or multidimensional arrays

【Function】
This function can be used to sort multiple arrays at once, or to sort multi-dimensional arrays according to a certain dimension or multiple dimensions
【Scope of use】
​​​​​ php4, php5.
【Use】
           bool array_multisort( array array1[,mixed array2[,mixed...[,array...]]] )
           arrayn/required/array to be sorted
The remaining parameters are arrays or flags
​​​​SORT_ASC Sort in ascending order
​​​​SORT_DESC Sort in descending order
SORT_REGULAR is to compare items according to the usual method
SORT_NUMERIC is to compare items based on numerical value
SORT_STRING is to compare items according to strings
The same kind of sorting flag cannot be specified after each array
The sort flag specified behind each array is only valid for that array. Before that, the default values ​​SORT_ASC and SORT_REGULAR
【Example】
[php]
$arr1 = array("10",100,100,"a");
$arr2 = array(1,3,"2",1);
array_multisort($arr1,$arr2);
var_dump($arr1);
var_dump($arr2);
/*
array(4) {
[0]=>
string(2) "10"
[1]=>
string(1) "a"
[2]=>
int(100)
[3]=>
int(100)
}
array(4) {
[0]=>
int(1)
[1]=>
int(1)
[2]=>
string(1) "2"
[3]=>
int(3)
}
*/


Excerpted from zuodefeng’s notes

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478217.htmlTechArticlearray_multisort() Sort multiple arrays or multi-dimensional arrays [Function] This function can be used to sort multiple arrays at one time Sort arrays, or sort multidimensional arrays according to one or more dimensions...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn