|
|
PHP Array Elements Sorting Function
|
Tutorials » Php »
|
Topic |
What is arsort() Function?
|
|
Explanation |
|
The "arsort()" function sorts an array elements by the values in reverse order, but the keys remain the same.
Syntax:
arsort(array,sorttype)
In the above syntax "array" is the array to be sorted, "sorttype" specifies the method to be used for sorting, it can have values
"SORT_REGULAR" for default, "SORT_NUMERIC" treat values numerically, "SORT_STRING" treat values as strings,"SORT_LOCALE_STRING"
treat values as strings based on local settings .
Example
<?php
$b=array("1"=>"Cherry","2"=>"Apple");
arsort($b);
print_r($b);
?>
Result:
Array ( [1] => Cherry [2] => Apple )
In the above example all the elements of the array "$b" is sorted using the default type "SORT_REGULAR"
and the keys remain the same.
|
|
A Note |
Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial.
Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.
|
|
|
|