Home >Backend Development >PHP Tutorial >Detailed introduction to php arsort array descending sorting

Detailed introduction to php arsort array descending sorting

高洛峰
高洛峰Original
2016-12-12 10:26:311830browse

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/>";
}
?>

Running result:

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


Statement:
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