PHP arsort Array Descending sort details _php instance

Source: Internet
Author: User

Arsort an array in descending order and maintains an indexed relationship.

Basic syntax

BOOL Arsort (array & $array [, int $sort _flags = sort_regular])

This function is sorted in descending order, and the index of the array is persisted and the cell is associated.

The Arsort function is primarily used to sort the associative arrays that are important to the order of the cells.

Parameter introduction:

Parameters Description
Array Necessary. The array entered.
Sort_flags

Optional. An element/item that prescribes how an array is arranged. Possible values:

  • 0 = sort_regular-default. Arrange each item in a regular order (Standard ASCII without changing the type)
  • 1 = sort_numeric-Treat each item as a number.
  • 2 = sort_string-handles each item as a string.
  • 3 = sort_locale_string-handles each item as a string, based on the current locale (which can be changed by setlocale ()).
  • 4 = sort_natural-handles each item as a string, using a natural sort similar to Natsort ().
  • 5 = sort_flag_case-the string can be sorted in combination (bitwise OR) sort_string or sort_natural, case-insensitive.

Description

The Arsort () function reverses the array and maintains an indexed relationship. It is primarily used to sort the associative arrays that are important to the order of the cells.

The optional second parameter contains an additional sort identity.

return value

Returns TRUE on success or FALSE on failure.

Instance:

<?php
$fruits = Array (
 "D" => "Lemon",
 "a" => "orange",
 "B" => "banana",
 "C" => " Apple "
);
Arsort ($fruits);
foreach ($fruits as $key => $val) {
 echo $key = $val <br/>;
}
? >  

Run Result:

A = Orange
D = Lemon
b = Banana
c = Apple

Thank you for reading, I hope to help you, thank you for your support for this site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.