توابع sort() در PHP
مثال
برای مرتب کردن عناصر آرایه $cars به ترتیب الفبایی به صورت افزایشی:
<?php $cars = array("Volvo", "BMW", "Toyota"); sort($cars); ?>
تعریف و استفاده
توابع sort() آرایههای شمارشی را به ترتیب افزایشی مرتب میکند.
توضیحات:این تابع به واحدهای آرایه کلید جدیدی اختصاص میدهد. کلیدهای موجود حذف خواهند شد.
Returns TRUE if successful, otherwise returns FALSE.
Tip:Please use rsort() The function sorts the index array in descending order.
Syntax
sort(array,sortingtype);
Parameters | Description |
---|---|
array | Required. Specify the array to be sorted. |
sortingtype |
Optional. Specify how to compare the elements/items of the array. Possible values:
|
Technical Details
Return Value: | Returns TRUE if successful, otherwise returns FALSE. |
PHP Version: | 4+ |
More Examples
Example 1
Sort the elements of the array $numbers in ascending order by number:
<?php $numbers=array(4,6,2,22,11); sort($numbers); ?>