sort
Sort arrays
sort()
function sorts the index array ascending order.
Note: This function assigns new key names to cells in an array. The original key name will be deleted.
Return TRUE if successful, otherwise return FALSE.
Tip: Please use the rsort()
function to sort the index array in descending order.
Sort the elements in the array $cars in ascending order:
<?php $cars = array ( "Volvo" , "BMW" , "Toyota" ) ; sort ( $cars ) ; ?>
Try it yourself
Sort the elements in the array $numbers in ascending order:
<?php $numbers = array ( 4 , 6 , 2 , 22 , 11 ) ; sort ( $numbers ) ; ?>
Try it yourself
sort ( array , sortingtype ) ;
parameter | describe |
---|---|
array | Required. Specifies the array to be sorted. |
sortingtype |
Optional. Specifies how to compare elements/items of an array. Possible values:
|