PHP Manual
Prev |  | Next

# krsort

krsort -- Sort an array by key in reverse order

## Description

`int krsort`(array array);

Sorts an array by key in reverse order, maintaining key to data correlations. This is useful mainly for associative arrays.

Example 1. krsort() example
    $fruits = array("d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple");
    krsort($fruits);
    for(reset($fruits); $key = key($fruits); next($fruits)) {
        echo "fruits[$key] = ".$fruits[$key]."\n";
    }

This example would display: `fruits[d] = lemon fruits[c] = apple fruits[b] = banana fruits[a] = orange`

See also asort(), arsort(), ksort() sort(), and rsort().

Prev | Home | Next
key | Up | ksort