- 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
krsort() function in PHP
The krsort() method sorts an array by key in reverse order. It returns TRUE on success or FALSE on failure.
Syntax
ksort(arr, flag)
Parameters
arr − The array to sort.
flag −
0 = SORT_REGULAR - Default. Compare items normally. Do not change types.
1 = SORT_NUMERIC - Compare items numerically
2 = SORT_STRING - Compare items as strings
3 = SORT_LOCALE_STRING - Compare items as strings, based on current locale
4 = SORT_NATURAL - Compare items as strings using natural ordering.
Return
The krsort() function returns TRUE on success or FALSE on failure.
Example
The following is an example −
<?php $product = array("p"=>"headphone", "r"=>"mouse", "q"=>"pendrive"); krsort($product); foreach ($product as $key => $val) { echo "$key = $val
"; } ?>
Output
The following is the output −
r = mouse q = pendrive p = headphone
Advertisements