Tutorials Point


  Learning PHP
  Advanced PHP
  PHP Function Reference
  PHP Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

PHP Function rsort()


previous

Advertisements

Syntax

rsort( $array [, $sort_flags] );

Definition and Usage

This function sorts an array in reverse order (highest to lowest).

This function assigns new keys for the elements in array. It will remove any existing keys you may have assigned, rather than just reordering the keys.

Paramters

ParameterDescription
arrayRequired. Specifies an array.
sort_flagsOptional. 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

Return Value

Returns TRUE on success or FALSE on failure.

Example

Try out following example:

<?php
$fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana" );
rsort($fruits);
print_r($fruits);
?> 

This will produce following result:

Array ( [0] => orange [1] => lemon [2] => banana )

previous Printer Friendly

Advertisements


  

Advertisements