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