PHP krsort

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP: krsort() function

PHP: Sort an array by key in reverse order

The krsort() function is used to sort an array by key in reverse order. Sorts an array by key in reverse order, maintaining a key to data correlations. The function is useful mainly for associative arrays.

Version

(PHP 4 and above)

Syntax

krsort(array_name, sort_type)

Parameters

Name

Description

Required /
Optional

Type

array_name

The argument to process in radians.

Required

Array

sort_type

Sets the sorting behavior. Possible Sorting type flags.
SORT_REGULAR - Compare items normally.
SORT_NUMERIC - Compare items numerically.
SORT_STRING - Compare items as strings.
SORT_LOCALE_STRING - compare items as strings, based on the current locale

Optional

Integer

Return value

TRUE on success or FALSE on failure.

Value Type : Boolean.

Pictorial Presentation :

php array krsort() function

Example :

  1. $w3r_array = array("x" => "html", "y" => "xhtml", "z" => "xml");  

  2. krsort($w3r_array);  

  3. print_r($w3r_array);  

  4. ?>  

Output :

Array ( [z] => xml [y] => xhtml [x] => html )