首页 > 文章列表 > php数组排序的函数有几个

php数组排序的函数有几个

php数组排
219 2022-08-06

本文操作系统: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";
}