Home >Backend Development >PHP Tutorial >Simple method to sort php array_PHP tutorial
The main requirements of this article introduce the use of PHP's own functions to achieve array sorting, including one-dimensional array ranking, multi-dimensional array sorting, random sorting, etc.
array_multisort($a,$b), $a,$b are two numbers
•The sort() function is used to sort array cells from low to high.
•rsort() function is used to sort array cells from high to low.
•asort() function is used to sort array cells from low to high and maintain index relationship.
•The arsort() function is used to sort the array cells from high to low and maintain the index relationship.
•The ksort() function is used to sort array cells from low to high by key name.
•The krsort() function is used to sort array cells from high to low by key name.
Sort multiple arrays
array_multisort($a,$b), $a,$b are two arrays. If after sorting, the third element of $a array is ranked first, then the third element of $b will not matter His size in $b will be ranked first. Take a look at the results of the program below:
The code is as follows
|
Copy code
|
||||||||||
?>
| |||||||||||
$array = array('A','2','3','4','5','6','7','8','9','10','J ','Q','K'); |