Thursday, 25 September 2014

rsort in PHP

PHP rsort() function is used to sort an array by values in reverse order.
PHP rsort() function returns TRUE on success, or FALSE on failure.

Syntax:


rsort(array,sorttype)
array : Required. Specifies the array to use.
sorttype : Optional. Specifies how to sort the array values.
    Possible values:

  • SORT_REGULAR - Default. Treat values as they are (don't change types)
  • SORT_NUMERIC - Treat values numerically
  • SORT_STRING - Treat values as strings
  • SORT_LOCALE_STRING - Treat values as strings, based on local settings

Example:


<?php
$daysarr = array( "a"=>"Sunday", "b"=>"Monday", "c"=>"Tuesday" );
rsort($daysarr);
print_r($daysarr);
?>

Output will be:


Array ( 
        [0] => Tuesday 
        [1] => Sunday 
        [2] => Monday 
      )

0 comments:

Post a Comment