ksort

(PHP3 , PHP4 )

ksort -- Sort an array by key

Description

int ksort (array array [, int sort_flags])

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

Példa 1. Ksort() example

  1 
  2 $fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
  3 ksort ($fruits);
  4 reset ($fruits);
  5 while (list ($key, $val) = each ($fruits)) {
  6     echo "$key -> $val\n";
  7 }
  8       

This example would display:

  1 
  2 fruits[a] = orange
  3 fruits[b] = banana
  4 fruits[c] = apple
  5 fruits[d] = lemon
  6       

You may modify the behavior of the sort using the optional parameter sort_flags, for details see sort().

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