PHP function asort() uses a specific method of sorting values ​​to parse_PHP tutorial

WBOY
Release: 2016-07-15 13:29:42
Original
991 people have browsed it

We mentioned in the previous article how to use the ksort() function to sort by keywords. So, today we will focus on how to sort arrays using values. In this process we will use the specific code of Listing E as follows:

<ol class="dp-xml">
<li class="alt">
<span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><LI class=alt><SPAN><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>data</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>array</FONT></SPAN><SPAN>("US" =</SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong></span><span> "United States", "IN" =</span><span class="tag"><strong><font color="#006699">></font></strong></span><span> <br>"India", "DE" =</span><span class="tag"><strong><font color="#006699">></font></strong></span><span> "Germany", "ES" =</span><span class="tag"><strong><font color="#006699">></font></strong></span><span> "Spain");<br>asort($data); print_r($data);  </span>
</li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
</li>
</ol>
Copy after login

below That's its output. Please note the difference between the results of the PHP function asort() and the results obtained using the ksort() function above - in both cases, the sorting is alphabetical, but they are sorted according to different fields of the array of.

At the same time, please note that the connection between keywords and values ​​will always be maintained; it is just a way to sort the keyword-value pairs, and the sorting will not change their correspondence.

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 get the value sorting of the array.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446351.htmlTechArticleWe mentioned in the previous article how to use the ksort() function to sort by keywords. So, today we will focus on how to sort arrays using values...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!