PHP数组排序之sort、asort与ksort用法实例_PHP

WBOY
Release: 2016-05-31 19:30:11
Original
1108 people have browsed it

本文实例讲解了PHP数组排序中sort、asort与ksort的用法,供大家参考借鉴之用。具体实例如下所示:

<&#63;php
$arr = array('d'=>'sdf', 'r'=>'sdf', 'a'=> 'eee');
//sort($arr);  // 对数组的值进行重排, 删除之前的键值, 变为索引数组
//asort($arr); // 对数组按照值进行重排,并保持索引关系,索引数组和关联数组均适用
ksort($arr); // 对数组按照键值进行重排,并保持索引关系,索引数组和关联数组均适用

// 对应逆序还有rsort arsort krsort
// 使用函数比较有usort uksort uasort  第二个参数为比较的函数 需要在第一个参数相等 小于 大于第二个参数时 返回 等于 小于 大于 0 的值 浮点数只会取整数部分

print_r($arr);
&#63;>

Copy after login

本文实例中仅对ksort用法做了示范,感兴趣的读者可以再测试sort与asort的运行结果,以便加深印象,牢固掌握。希望本文实例对大家PHP程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!