Php array sorting-sort element key names in ascending order _ PHP Tutorial

Source: Internet
Author: User
Php array sorting-sort the key names of elements in the array in ascending order. Php array sorting sorts the key names of elements in the array in ascending order and maintains the index relationship. For more information, see. This function is used by the ksort () function to sort the element key names of the array in ascending order and maintain the index relationship. For more information, see.

This function is
The ksort () function sorts the array in ascending order by key name and retains the original key for the array value.

The second optional parameter contains an additional sorting flag.

If yes, TRUE is returned. otherwise, FALSE is returned.

Syntax
Ksort (array, sorttype) parameter description
Array is required. Specifies the array to be sorted.
Sorttype is optional. Specifies how to arrange the values of an array. Possible values:

SORT_REGULAR-default. Process with their original type (without changing the type ).
SORT_NUMERIC-process the value as a number
SORT_STRING-process the value as a string
SORT_LOCALE_STRING-process the value as a string based on local settings *.

*: This value is newly added to PHP 4.4.0 and 5.0.2. Before PHP 6, you can use setlocale () to change the region settings of the system. From PHP 6, you must use the i18n_loc_set_default () function.

Example

The code is as follows:

$ My_array = array ("e" => "Dog", "B" => "Cat", "c" => "Horse ");
Ksort ($ my_array );
Print_r ($ my_array );
?> Output:

Array ([B] => Cat [c] => Horse [e] => Sog)

Bytes. This time, The ksort () function upgrades the array according to the key name...

Related Article

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.