sort

sort -- Sort an array

Description

void sort(array array);

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

Example 1. sort() example

  1 
  2 $fruits = array ("lemon", "orange", "banana", "apple");
  3 sort ($fruits);
  4 for (reset ($fruits); $key = key ($fruits); next ($fruits)) {
  5     echo "fruits[$key] = ".$fruits[$key]."\n";
  6 }
  7       
This example would display: fruits[0] = apple fruits[1] = banana fruits[2] = lemon fruits[3] = orange The fruits have been sorted in alphabetical order.

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