sort

(PHP3 , PHP4 )

sort -- Sort an array

Description

void sort (array array [, int sort_flags])

This function sorts an array. Elements will be arranged from lowest to highest when this function has completed.

Példa 1. Sort() example

  1 
  2 $fruits = array ("lemon", "orange", "banana", "apple");
  3 sort ($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[0] = apple
  3 fruits[1] = banana
  4 fruits[2] = lemon
  5 fruits[3] = orange
  6       

The fruits have been sorted in alphabetical order.

The optional second parameter sort_flags may be used to modify the sorting behavior using theese valies:

Sorting order flags:

Sorting type flags:

See also: arsort(), asort(), ksort(), rsort(), and usort().