English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP krsort() function usage and example

PHP Array Function Manual

The krsort() function sorts the array in reverse order by key name

Syntax

krsort ( $array, $sort_flag );

Definition and usage

The krsort() function sorts the array in reverse order by key. These values retain their original keys.

Parameter

Serial numberParameters and descriptions
1

array(required)

It specifies an array

2

sort_flag(optional)

It specifies how to sort the array values. Possible values-

  • SORT_REGULAR - Default value. Treat the value as is (do not change the type)

  • SORT_NUMERIC - Process the value numerically

  • SORT_STRING - Treat the value as a string

  • SORT_LOCALE_STRING - Treat the value as a string according to the local settings

Return value

This function returns TRUE on success and FALSE on failure.

Online example

<?php
   $transport = array( 'a'=>'foot', 'b'=>'bike', 'c'=>'car', 'd'=>'plane');
   krsort($transport);
   print_r($transport);
?>
Test and see‹/›

Output result:

Array ( [d] => plane [c] => car [b] => bike [a] => foot )

  PHP Array Function Manual