PHP arsort Array Descending sort details _php instances

Source: Internet
Author: User
The PHP arsort function is used to sort the elements in the array in descending order, if the sort succeeds returns True, otherwise returns false, this article explains the basic syntax of the Arsort function and the use of examples, the need for friends can refer to the following

Arsort the array in descending order and maintains the index relationship.

Basic syntax

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

This function sorts the arrays in descending order, the index of the array remains and the cell is associated.

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

Parameter description:

Parameters Description
Array Necessary. The input array.
Sort_flags

Optional. Specifies how to arrange the elements/items of an array. Possible values:

  • 0 = sort_regular-default. Arrange each item in the usual order (standard ASCII, no change type)

  • 1 = sort_numeric-Each item is treated as a number.

  • 2 = sort_string-Each item is treated as a string.

  • 3 = sort_locale_string-handles each item as a string, based on the current locale (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-You can sort strings by combining (bitwise OR) sort_string or sort_natural, not case-sensitive.

Description

The Arsort () function reverses the array and maintains the index relationship. It is primarily used to sort the associative arrays that are important for the cell order.

The Second optional parameter contains an additional sort ID.

return value

Returns TRUE on success, or FALSE on failure.

Instance:

<?php$age=array ("Bill" = "the", "Steve" and "the", "Mark" = "31"); Arsort ($age);? 

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.