php数组排序字典序

发布时间:2020-12-06 19:16:08 阅读:1901次

php中我们经常需要对数组进行排序

比如按照键名来排序,按照键值来排序

sort() 函数用于对数组单元从低到高进行排序。

rsort() 函数用于对数组单元从高到低进行排序。

asort() 函数用于对数组单元从低到高进行排序并保持索引关系。

arsort() 函数用于对数组单元从高到低进行排序并保持索引关系。

ksort() 函数用于对数组单元按照键名从低到高进行排序。

krsort() 函数用于对数组单元按照键名从高到低进行排序。

MacBook-Air:~ test$ cat 1
<?php
$aa = array(
    'the'=>'world','hello'=>'one','world'=>"the"
);
print_r($aa);
print_r("<br>");
ksort($aa);
print_r($aa);

输出

MacBook-Air:~ test$ php 1
Array
(
    [the] => world
    [hello] => one
    [world] => the
)
<br>Array
(
    [hello] => one
    [the] => world
    [world] => the
)

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:php数组排序字典序 出自老鄢博客 | 欢迎分享