PHP

PHP Menu

PHP

krsort() Function - Definition, Syntax, Parameters, Examples

Definition

The krsort() function sorts an associative array in descending order, according to the key (key-value mapping is preserved).

Syntax

krsort(array, sorttype)

Parameters

Parameter Description
array Required. Specifies the array to sort.
sorttype Optional. Possible values:
0 = SORT_REGULAR - Default. Compare items normally (don't change types)
1 = SORT_NUMERIC - Compare items numerically
2 = SORT_STRING - Compare items as strings
3 = SORT_LOCALE_STRING - Compare items as strings, based on current locale
4 = SORT_NATURAL - Compare items as strings using natural ordering
5 = SORT_FLAG_CASE - Can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort strings case-insensitively

Example

<?php
$ages = array("Mark" => 22, "Jeff" => 32, "Mike" => 28); krsort($ages); print_r($ages);

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods