Thursday, 25 September 2014

arsort in PHP

arsort() function is utilized to sort a data array in converse request.
The definitive keys relating to values are kept as same.
PHP arsort() function returns True for success, or False on inadequacy.

Syntax:

 arsort(array,sorttype)
array : Required. Specifying an array
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
$daysarr1 = array( "a"=>"Sunday","b"=>"Monday","c" =>"Tuesday" );
arsort($daysarr1);
print_r($daysarr1);
?>

Output will be:

Array ( 
         [c] => Tuesday
         [a] => Sunday 
         [b] => Monday 
        )

0 comments:

Post a Comment