PHP sort () function
Examples
$ Cars array elements in alphabetical ascending order:
<?php
$cars=array("Volvo","BMW","Toyota");
sort($cars);
?>
$cars=array("Volvo","BMW","Toyota");
sort($cars);
?>
Running instance »
Definition and Usage
sort () function array of numeric values in descending order.
Tip: Use rsort () function array of numeric values in descending order.
grammar
sort( array,sortingtype );
参数 | 描述 |
---|---|
array | 必需。规定要进行排序的数组。 |
sortingtype | 可选。规定如何排列数组的元素/项目。可能的值:
|
technical details
return value: | If successful it returns TRUE, on failure returns FALSE. |
---|---|
PHP version: | 4+ |
More examples
Example 1
$ Numbers array elements in ascending order by numbers:
<?php
$numbers=array(4,6,2,22,11);
sort($numbers);
?>
$numbers=array(4,6,2,22,11);
sort($numbers);
?>
Running instance »
Complete PHP Array Reference