- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
arsort() function in PHP
The arsort() function sorts an array in reverse order and maintain index association.
Syntax
arsort(arr, compare)
Parameters
arr − The specified array.
compare − Specifies how to compare the array elements/items. Possible values −
SORT_STRING - Compare items as strings
SORT_REGULAR - Compare items without changing types
SORT_NUMERIC - Compare items numerically
SORT_LOCALE_STRING - Compare items as strings, based on current local.
SORT_NATURAL - Compare items as strings using natural ordering
Return
The arsort() function returns TRUE on success and FALSE on failure.
Example
The following is an example −
<?php $rank = array("Australia"=>2,"India"=>5,"Bangladesh"=>9); arsort($rank); foreach($rank as $akey=>$avalue) { echo "Key=" . $akey . " : Value=" . $avalue; echo "<br>"; } ?>
Output
The following is the output −
Key=Bangladesh : Value=9 Key=India : Value=5 Key=Australia : Value=2
Advertisements