توابع rsort() در PHP
مثال
عناصر آرایهی $cars را به ترتیب الفبایی به صورت کاهشی مرتب میکند:
<?php $cars = array("Volvo", "BMW", "Toyota"); rsort($cars); ?>
تعریف و کاربرد
توابع rsort() آرایهی عددی را به ترتیب کاهشی مرتب میکند.
توضیحات:لطفاً از sort() این تابع آرایهی عددی را به ترتیب تصاعدی مرتب میکند.
نحوهی نوشتن
rsort(array,sortingtype);
پارامتر | توضیح |
---|---|
array | ضروری. آرایهای که قرار است مرتب شود را تعیین میکند. |
sortingtype |
اختیاری. روش مقایسهی عناصر/آیتمهای آرایه را تعیین میکند. مقادیر ممکن:
|
Description
The rsort() function sorts the elements of the array in reverse order by key value. It is basically the same as the function of arsort().
Note:This function is array Assigns new key names to the units. This will delete the original key names and not just reorder them.
Returns TRUE if successful, otherwise FALSE.
The optional second parameter contains additional sorting flags.
Technical Details
Return Value: | TRUE on success. FALSE on failure |
PHP Version: | 4+ |
More Examples
Example 1
Sort the elements in the array $numbers in descending order by number:
<?php $numbers = array(4, 6, 2, 22, 11); rsort($numbers); ?>
Example 2
Compare the items as numbers and sort the elements in the array $cars in descending order:
<?php $cars = array("Volvo", "BMW", "Toyota"); rsort($cars, SORT_NUMERIC); ?>