Monday, 26 August 2013

PHP Function krsort()

Syntax

krsort ( $array, $sort_flag );

Definition and Usage

The krsort() function sorts an array by the keys in reverse order. The values keep their original keys.

Paramters

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

This function returns TRUE on success, or FALSE on failure.

Example

Try out following example:
<?php
$transport = array( a=>'foot', b=>'bike', c=>'car', d=>'plane');
krsort($transport);
print_r($transport);
?> 
This will produce following result:
Array ( [d] => plane [c] => car [b] => bike [a] => foot )

No comments:

Post a Comment