ksort

ksort -- Sort an array by key

Description

int ksort(array array);

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

Example 1. ksort() example

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

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