![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
uksort() function in PHP
The uksort() function sorts an array by keys using a user-defined function. It returns TRUE on success and FALSE on failure.
Syntax
uksort(arr, custom_function)
Parameters
arr − The specified array.
custom_function − The comparison function. It must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
Return
The uksort() function returns TRUE on success and FALSE on failure.
Example
The following is an example −
<?php function display($x,$y) { if ($x==$y) return 0; return ($x<$y)?-1:1; } $myarr = array("a"=>99,"b"=>27,"c"=>56); uksort($myarr,"display"); foreach($myarr as $x=>$x_value) { echo "Key=" . $x . " Value=" . $x_value; echo "<br>"; } ?>
Output
Key=a Value=99 Key=b Value=27 Key=c Value=56
Advertisements