Maison >développement back-end >tutoriel php >PHP函数arsort()的功能特点详解_PHP教程
大家在学习以下Listing F的代码就是PHP函数arsort()的使用示例:
<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> <li class="alt"><span><span></span></span></li> <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">></font></strong></span><span> "United States", "IN" <br>=</span><span class="tag"><strong><font color="#006699">></font></strong></span><span> "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> <br>"Spain");arsort($data); print_r($data); </span></span></li> <li class=""><span class="tag"></span></li> <li class=""> <span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span> </li> </ol>
下面是它的输出结果,根据值按字母表顺序进行倒排。将下面的结果与用krsort()函数进行倒排后生成的结果进行比较,就能很容易明白两者的不同了。
Array ([US] => United States
[ES] => Spain
[IN] => India
[DE] => Germany
)
以上介绍的示例就是PHP函数arsort()的具体使用方式。