PHP function asort () parsing by specific method of value sorting _ PHP Tutorial

Source: Internet
Author: User
PHP function asort () is parsed by sorting values. We mentioned in the previous article how to use the ksort () function to sort by keywords. So today we will focus on how to use values to sort arrays. We mentioned in the previous article how to use the ksort () function to sort arrays by keywords. Today, we will focus on how to sort arrays by values. In this process, we will useThe specific code of Listing E is as follows:

 
 
  1. php
  2. $data = array("US" => "United States", "IN" =>
    "India", "DE" => "Germany", "ES" => "Spain");
    asort($data); print_r($data);
  3. ?>

The output result is as follows. Note that the results of the PHP function asort () are different from those obtained by using the ksort () function. In both cases, the results are sorted alphabetically, however, they are sorted based on different fields of the array.

At the same time, note that the relationship between the key-value pairs is always maintained. it is only a method after the key-value pairs are sorted, and their correspondence is not changed.

Array ([DE] => Germany

[IN] => India

[ES] => Spain

[US] => United States

)

The above code example is the specific application of the PHP function asort (). we can use this function to sort the values of the array.


Sort () functions sort by keywords. So, today we will focus on how to use values to arrange arrays...

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.