Sort an array by its values from lowest to highest. All of the keys are lost as it is re-indexed as a numerically indexed array. Only true or false is returned (success or failure). This function alters the input array itself.

To sort from highest to lowest, see rsort() which works the same as this function.

Optional flags can be used as the second parameter. SORT_REGULAR is the default.

SORT_REGULAR Compare items normally (don’t change types)
SORT_NUMERIC Compare items numerically
SORT_STRING Compare items as strings
SORT_LOCALE_STRING Compare items as strings, based on the current locale.

If the values are of mixed types, you may not get the result you expect in some cases.

$arr = array('eggplant',
             'banana',
             'apple',
             'dandelion',
             'carrot');
sort($arr);
/*
array (
  0 => 'apple',
  1 => 'banana',
  2 => 'carrot',
  3 => 'dandelion',
  4 => 'eggplant'
)
*/
 
$arr = array('test' => 'eggplant',
             'banana',
             'sample' => 'apple',
             17 => 'dandelion',
             'carrot');
sort($arr);
/*
array (
  0 => 'apple',
  1 => 'banana',
  2 => 'carrot',
  3 => 'dandelion',
  4 => 'eggplant'
)
*/
 
$arr = array('25',
             43,
             8004,
             3,
             '8004',
             0,
             -52);
sort($arr);
/*
array (
  0 => -52,
  1 => 0,
  2 => 3,
  3 => '25',
  4 => 43,
  5 => '8004',
  6 => 8004
)
*/
 
$arr = array('25',
             43,
             8004,
             3,
             '8004',
             0,
             -52);
sort($arr, SORT_STRING);
/*
array (
  0 => -52,
  1 => 0,
  2 => '25',
  3 => 3,
  4 => 43,
  5 => 8004,
  6 => '8004'
)
*/