PHP sort()Functions
Examples
Sort the elements of the array $cars in alphabetical ascending order:
$cars=array("Volvo","BMW","Toyota");
sort($cars);
Run example »
Definition and Usage
The sort() function sorts an indexed array in ascending order.
Tip:Please usersort()function to sort numeric arrays in descending order.
Syntax
sort(array,sortingtype);
| Parameter | Description |
|---|---|
| array | Required. Specifies the array to sort. |
| sortingtype | Optional. Specifies how to arrange the elements/items of the array. Possible values:
|
Technical Details
| Return value: | Returns TRUE on success or FALSE on failure. |
|---|---|
| PHP Version: | 4+ |
More Examples
Example 1
Sort the elements of the array $numbers in ascending numeric order:
<?php
$numbers=array(4,6,2,22,11);
sort($numbers);
?>
$numbers=array(4,6,2,22,11);
sort($numbers);
?>
Run example »
Complete PHP Array Reference Other Extensions