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

  1 
  2 $fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
  3 krsort ($fruits);
  4 for (reset ($fruits); $key = key ($fruits); next ($fruits)) {
  5     echo "fruits[$key] = ".$fruits[$key]."\n";
  6 }
  7       
This example would display: fruits[d] = lemon fruits[c] = apple fruits[b] = banana fruits[a] = orange

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