Detailed introduction to php arsort array descending sorting

高洛峰
Release: 2023-03-03 13:56:01
Original
1794 people have browsed it

arsort sorts an array in descending order and maintains index relationships.

Basic syntax

bool arsort ( array &$array [, int $sort_flags = SORT_REGULAR ] )

This function sorts the array in descending order, and the index of the array remains associated with the unit. The

arsort function is mainly used to sort associative arrays where the order of units is important.

Parameter introduction:

Detailed introduction to php arsort array descending sorting

Description

arsort() function reversely sorts the array and maintains the index relationship. Mainly used for sorting associative arrays where the order of cells is important.

The optional second parameter contains additional sorting flags.

Return Value

Returns TRUE on success, or FALSE on failure.

Example:

<?php
$fruits = array(
 "d" => "lemon",
 "a" => "orange",
 "b" => "banana",
 "c" => "apple"
);
arsort($fruits);
foreach ($fruits as $key => $val) {
 echo " $key = $val <br/>";
}
?>
Copy after login

Running result:

a = orange
d = lemon
b = banana
c = apple


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