PHP Sort function Learning _php tutorial

Source: Internet
Author: User

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

Returns TRUE if successful, otherwise FALSE.

$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 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.

Returns TRUE if successful, otherwise FALSE.

$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, preserving the original key for the array value.

The Second optional parameter contains an additional sort flag. Www.jbxue.com

Returns TRUE if successful, otherwise FALSE is returned.

$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 the key name, the key value, whether to change the index or not

>>> articles you may be interested in:
< span="">
< span="">
< span="">
< span="">
< span="">
< span="">
< span="">
< span="">

http://www.bkjia.com/PHPjc/738552.html www.bkjia.com true http://www.bkjia.com/PHPjc/738552.html techarticle Note: This function assigns the new key name to the cells in the array. The original key name is deleted. Returns TRUE if successful, otherwise FALSE. php $my _array = Array ("A" = "Dog", "B ...

  • 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.