博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
krsort_PHP krsort()函数与示例
阅读量:2530 次
发布时间:2019-05-11

本文共 1764 字,大约阅读时间需要 5 分钟。

krsort

PHP krsort()函数 (PHP krsort() function)

krsort() function is used to sort an associative array in descending order based on the keys, as we know that an associative array contains keys and values, this method sorts an array according to the keys.

krsort()函数用于根据键对降序排列的关联数组进行排序,因为我们知道关联数组包含键和值 ,因此该方法根据键对数组进行排序。

It does not return a sorted array, it sorts the input array.

它不返回已排序的数组,而是对输入数组进行排序。

Syntax:

句法:

krsort(array, [mode]);

Here,

这里,

  • array is an input array

    数组是输入数组

  • mode is an optional parameter, its default value is 0, it has following values:

    mode是一个可选参数,其默认值为0,它具有以下值:

    0 – It is used to compare items normally

    0 –用于正常比较项目

    1 – It is used to compare items numerically

    1 –用于数字比较项目

    2 – It is used to compare items as strings

    2 –用于比较项目作为字符串

    3 – It is used to compare items as current locale strings

    3 –用于比较项目作为当前区域设置字符串

    4 – It is used to compare items as strings (natural ordering)

    4 –用于将项目作为字符串进行比较(自然顺序)

Examples:

例子:

Input:    $person = array(        "radib" => 21,        "amit" => 21,        "abhi" => 20,        "prem" => 27,        "manju" => 25        );    Output:    sorted array...      Array    (            [radib] => 21        [prem] => 27         [manju] => 25        [amit] => 21         [abhi] => 20     )

PHP code:

PHP代码:

21, "amit" => 21, "abhi" => 20, "prem" => 27, "manju" => 25 ); print ("unsorted array...\n"); print_r ($person); //sorting... krsort($person); print ("sorted array...\n"); print_r ($person); ?>

Output

输出量

unsorted array...Array(        [radib] => 21    [amit] => 21     [abhi] => 20     [prem] => 27     [manju] => 25)    sorted array...  Array(        [radib] => 21    [prem] => 27     [manju] => 25    [amit] => 21     [abhi] => 20 )

翻译自:

krsort

转载地址:http://hmxzd.baihongyu.com/

你可能感兴趣的文章
LuoguP4012 深海机器人问题(费用流)
查看>>
自动机
查看>>
java知识点
查看>>
WPF设计の画刷(Brush)
查看>>
HTML学习笔记
查看>>
selinux详解及配置文件
查看>>
性能优化之数据库优化
查看>>
Swift - 继承UIView实现自定义可视化组件(附记分牌样例)
查看>>
android自定义viewgroup实现等分格子布局
查看>>
springboot 配置mybatis
查看>>
10慕课网《进击Node.js基础(一)》初识promise
查看>>
JavaScript事件
查看>>
mysql 命令之工作小结
查看>>
linux 系统下 tar 的压缩与解压缩命令
查看>>
阿里负载均衡,配置中间证书问题(在starcom申请免费DV ssl)
查看>>
转:How to force a wordbreaker to be used in Sharepoint Search
查看>>
MySQL存储过程定时任务
查看>>
UVa 1658,Admiral (拆点+限制最小费用流)
查看>>
Python中and(逻辑与)计算法则
查看>>
POJ 3267 The Cow Lexicon(动态规划)
查看>>