PHP krsort() Function

0

The krsort() function sorts an associative array in descending order, according to the key.

Tip: Use the ksort() function to sort an associative array in ascending order, according to the key.

Tip: Use the arsort() function to sort an associative array in descending order, according to the value.

Parameter Description
array Required. Specifies the array to sort
sortingtype Optional. Specifies how to compare the array elements/items. Possible values:

Syntax

krsort(array,sortingtype);

Example

$age=array("Alex"=>"35","Cooper"=>"37","Samuel"=>"43");
krsort($age);
print_r($age);

Output

Array ( [Samuel] => 43 [Cooper] => 37 [Alex] => 35 )