Sort the elements of the $a array using a user-defined comparison function:
<?phpfunction my_sort($a,$b){if ($a==$b) return 0;return ($a<$b)?-1:1;}$a=array(4,2,8, 6);usort($a,"my_sort");?>usort() sorts an array using a user-defined comparison function.
usort( array,myfunction );
parameter | describe |
---|---|
array | Required. Specifies the array to be sorted. |
myfunction | Optional. A string that defines a callable comparison function. If the first parameter <, =, > the second parameter, the corresponding comparison function must return an integer <, =, > 0. |
Return value: | Returns TRUE if successful and FALSE if failed. |
---|---|
PHP version: | 4+ |