Sort the elements of the $arr array by values using a user-defined comparison function in PHP
Description
The following code shows how to sort the elements of the $arr array by values using a user-defined comparison function.
Example
/*from ww w . j ava 2 s .c o m*/
<?php
function my_sort($a,$b){
if ($a==$b)
return 0;
return ($a<$b)?-1:1;
}
$arr=array("a"=>4,"b"=>2,"c"=>8,d=>"6");
uasort($arr,"my_sort");
?>