Heim > Artikel > Backend-Entwicklung > PHP函数Ksort()通过关键字对数组进行排序的具体方式介绍_PHP教程
我们在学习Listing C的具体代码如下:
<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 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", <br>"IN" =</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");ksort($data); print_r($data); </span></span></li> <li class=""> <span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span> </li> </ol>
它的输出结果如下:
Array ([DE] => Germany
[ES] => Spain
[IN] => India
[US] => United States
)
通过上面例子的介绍,希望大家能清楚PHP函数Ksort()的具体使用。