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:
- php
- $data = array("US" => "United States", "IN" =>
"India", "DE" => "Germany", "ES" => "Spain");
asort($data); print_r($data);
- ?>
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...