Sort () Definition and usage
The sort () function sorts the values of the given array in ascending order.
Note: This function assigns a new key name to the cell in the array. The original key name was deleted.
Returns TRUE if successful, otherwise returns FALSE.
Grammar
Sort (array,sorttype) parameter description
Array required. The array entered.
SortType Optional. Specify how to arrange the values of the array. Possible values:
Sort_regular-Default. Processed in their original type (without changing the type).
Sort_numeric-Handle the value as a number
Sort_string-Handle the value as a string
Sort_locale_string-handles values as strings, based on local settings *.
*: This value is a new addition to PHP 4.4.0 and 5.0.2. Before PHP 6, the locale of the system was used and can be changed with setlocale (). From PHP 6, you must use the I18n_loc_set_default () function.
Example
Copy Code code as follows:
<?php
$my _array = Array ("A" => "Dog", "B" => "Cat", "C" => "horse");
Sort ($my _array);
Print_r ($my _array);
?>
Output:
Array
(
0] => Cat
[1] => Dog
[2] => Horse
)