PHP arsort() function

P
PHP array_walk_recursive() function
PHP asort() function

The arsort function sorts an associative array in descending order based on the values.

What is the syntax of arsort function in PHP?

arsort(array, sorttype)
ParameterDescription
arrayThe array to sort – Required
sorttypeOptional. Specifies how to compare the array elements/items. SORT_STRING (default) – Compare elements as strings
SORT_REGULAR – Compares normally without changing the type
SORT_NUMERIC – Compare as numeric values
SORT_LOCALE_STRING – Compare as a string according to the current locale
arsort function in PHP

Example of arsort function

Example 1. Sort an associative array in descending order according to its values.

<?php
$age=array("Jawad"=>"24","Ahmad"=>"25","Sumerina"=>"39");
arsort($age);
?>
PHP array_walk_recursive() function
PHP asort() function

Add comment

Tutor Network

Share this

Learn PHP from A to Z