Php sorting Function Learning

Source: Internet
Author: User

Note: This function assigns a new key name to the cell in the array. The original key name is deleted.

If the call succeeds, TRUE is returned. Otherwise, FALSE is returned.

<? Php
$ My_array = array ("a" => "Dog", "B" => "Cat", "c" => "Horse ");

Sort ($ my_array );
Print_r ($ my_array );
?>
Output:
Array
(
[0] => Cat
[1] => Dog
[2] => Horse
)
The asort () function sorts arrays and maintains the index relationship. It is mainly used to sort the arrays that are very important to the unit order.

The second optional parameter contains an additional sorting identifier.

If the call succeeds, TRUE is returned. Otherwise, FALSE is returned.

<? Php
$ My_array = array ("a" => "Dog", "B" => "Cat", "c" => "Horse ");

Asort ($ my_array );
Print_r ($ my_array );
?>
Output:

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

The ksort () function sorts the array by key name and retains the original key for the array value.

The second optional parameter contains an additional sorting flag. Www.jbxue.com

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

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

Array
(
[A] => Dog
[B] => Cat
[C] => Horse
)
The above three functions differ in key names, key values, and whether to change indexes.

>>> Articles you may be interested in:







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.