Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

arsort()

Rank values from largest to smallest in the original map.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

arsort(array &$array, int $flags = SORT_REGULAR): true

Rank values from largest to smallest in the original map. Keys stay attached to their values and ties keep their input order in PHP 8. Use SORT_NUMERIC for numeric ranks. The return value is true; read the reordered array from the argument.

Signature

arsort(array &$array, int $flags = SORT_REGULAR): true

Example output

[true,["rain","snow","sun"]]

Examples

<?php
$scores = ["sun"=>4, "rain"=>7, "snow"=>7];
$ok = arsort($scores, SORT_NUMERIC);
echo json_encode([$ok, array_keys($scores)]);

Result

[true,["rain","snow","sun"]]

Sources