PHP Array function sequence Krsort ()-an array of element key names in descending order, keeping the index relationship _php skills

Source: Internet
Author: User
Tags numeric value
Krsort () Definition and usage
The Krsort () function sorts the array in reverse order, preserving the original key for the numeric value.

The optional second parameter contains the additional sort flags.

If successful, returns TRUE, otherwise returns FALSE.

Grammar
Krsort (array,sorttype) parameter description
Array required. Specify the array to sort.
SortType Optional. Specify how to arrange the values of the array. Possible values:

Sort_regular-Default. Processed in their original type (without changing the type).
Sort_numeric-Handle the value as a number
Sort_string-Handle the value as a string
Sort_locale_string-handles values as strings, based on local settings *.


*: This value is a new addition to PHP 4.4.0 and 5.0.2. Before PHP 6, the locale of the system was used and can be changed with setlocale (). From PHP 6, you must use the I18n_loc_set_default () function.

Example
Copy Code code as follows:

<?php
$my _array = Array ("A" => "Dog", "B" => "Cat", "C" => "horse");
Krsort ($my _array);
Print_r ($my _array);
?>

Output:

Array
(
[C] => Horse
[b] => Cat
[A] => Dog
)

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.