How to use krsort function

藏色散人
Release: 2023-04-05 08:30:02
Original
1981 people have browsed it

php The krsort() function is used to sort the array in reverse order by key name.

How to use krsort function

php krsort() function syntax

Function: Sort the associative array in descending order according to the key name

Syntax:

krsort(array,sortingtype)
Copy after login

Parameters:

array Required. Specifies the array to be sorted.

sortingtype Optional. Specifies how the elements/items of an array are arranged. Possible values: 0 = SORT_REGULAR - Default. Put each item in regular order (Standard ASCII, don't change the type). 1 = SORT_NUMERIC - treat each item as a number. 2 = SORT_STRING - Treat each item as a string. 3 = SORT_LOCALE_STRING - Treat each item as a string, based on the current locale (can be changed with setlocale()). 4 = SORT_NATURAL - Treat each item as a string, using natural sorting like natsort(). 5 = SORT_FLAG_CASE - Strings can be sorted in combination (bitwise OR) with SORT_STRING or SORT_NATURAL, case-insensitively.

Description: Sort the array by key name and retain the original keys for the array values. The optional second parameter contains additional sorting flags. Returns TRUE if successful, FALSE otherwise.

php krsort() function example

<?php
$age=array("西门"=>"60","无忌"=>"31","灭绝"=>"56");
krsort($age);
print_r($age);
?>
Copy after login

Output:

Array ( [西门] => 60 [灭绝] => 56 [无忌] => 31 )
Copy after login

This article is an introduction to the PHP krsort function. I hope it will be helpful to friends in need!

The above is the detailed content of How to use krsort function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template