โ— Shell
clean mode source โ†—

PHP: krsort - Manual

(PHP 4, PHP 5, PHP 7, PHP 8)

krsort โ€” Sort an array by key in descending order

Description

Note: If two members compare as equal, they retain their original order. Prior to PHP 8.0.0, their relative order in the sorted array was undefined.

Note: Resets array's internal pointer to the first element.

Return Values

Always returns true.

Changelog

Version Description
8.2.0 The return type is true now; previously, it was bool.
8.2.0 This function now does numeric string comparison under SORT_REGULAR using the standard PHP 8 rules.

Examples

Example #1 krsort() example

<?php
$fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
krsort($fruits);
foreach ($fruits as $key => $val) {
    echo "$key = $val\n";
}
?>

The above example will output:

d = lemon
c = apple
b = banana
a = orange

See Also

Found A Problem?

There are no user contributed notes for this page.