Home >Backend Development >PHP Tutorial >How to use the arsort function
php arsort() function is used to reverse sort the array and maintain the index relationship.
php arsort() function syntax
Function: Sort the associative array in descending order according to the key value
Syntax:
arsort(array,sortingtype)
Parameters:
array required. Specifies the array to be sorted.
sortingtype Optional. Specifies how the elements/items of an array are arranged. Possible values: 0 = SORT_REGULAR - Default. Put each item in regular order (Standard ASCII, don't change the type). 1 = SORT_NUMERIC - treat each item as a number. 2 = SORT_STRING - Treat each item as a string. 3 = SORT_LOCALE_STRING - Treat each item as a string, based on the current locale (can be changed with setlocale()). 4 = SORT_NATURAL - Treat each item as a string, using natural sorting like natsort(). 5 = SORT_FLAG_CASE - Strings can be sorted in combination (bitwise OR) with SORT_STRING or SORT_NATURAL, case-insensitively.
Description: Reverse sort the array and maintain the index relationship. Mainly used for sorting associative arrays where the order of cells is important. The optional second parameter contains additional sorting flags. Returns TRUE if successful, FALSE otherwise.
php arsort() function example
<?php $age=array("西门"=>"60","灭绝"=>"56","无忌"=>"31"); arsort($age); print_r($age); ?>
Output:
Array ( [西门] => 60 [灭绝] => 56 [无忌] => 31 )
This article is an introduction to the PHP arsort function. I hope it will be helpful to friends who need it. Helps!
The above is the detailed content of How to use the arsort function. For more information, please follow other related articles on the PHP Chinese website!