ITPub博客

首页 > IT职业 > IT职场 > php数组排序的函数有几个

php数组排序的函数有几个

IT职场 作者:populace 时间:2021-09-11 10:01:50 0 删除 编辑

本文操作系统:windows7系统、PHP5.6版本、DELL G3电脑。

1.排序函数

sort() - 对数组进行升序排列

rsort() - 对数组进行降序排列

asort() - 根据关联数组的值,对数组进行升序排列

ksort() - 根据关联数组的键,对数组进行升序排列

arsort() - 根据关联数组的值,对数组进行降序排列

krsort() - 根据关联数组的键,对数组进行降序排列

2.sort 函数

<?php
 
$sec = "ailx10,ailx12,ailx13,ailx11";
$hack = explode(",",$sec);
sort($hack);
$sec2 = implode(",",$hack);
print "排序前:" . $sec ."n";
print "排序后:" . $sec2;

3.asort 函数

<?php
 
$hack_biji = array("黑客" =>"hacker",
    "网络安全" =>"net_sec",
    "人工智能"=>"AI");
 
asort($hack_biji);
 
print "排序后:";
foreach ($hack_biji as $key => $value){
    print "$key ==> $value n";
}

以上就是php数组排序6种函数,相信大家已经对它们有了一个大致的印象,学会后就可以把这些函数保存下来,方便下次的复习和使用。更多php学习指路:php数组

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3026/viewspace-2831094/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: javajsp是什么
请登录后发表评论 登录
全部评论

注册时间:2019-08-30

  • 博文量
    74
  • 访问量
    488