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代码:

<?php
$person = array(
"radib" => 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
)

翻译自: https://www.includehelp.com/php/krsort-function-with-example.aspx

krsort

krsort_PHP krsort()函数与示例相关推荐

  1. krsort函数怎么用php,krsort函数怎么用

    php krsort()函数用于对数组按照键名逆向排序. php krsort()函数 语法 作用:按照键名对关联数组进行降序排序 语法:krsort(array,sortingtype) 参数: a ...

  2. php指定长度 分割整形,php指定长度分割字符串str_split函数用法示例

    本文实例讲述了php指定长度分割字符串str_split函数用法.分享给大家供大家参考,具体如下: 示例1:$str = 'abcdefgh'; $arr = str_split($str,2); 运 ...

  3. getdate函数_PHP getdate()函数与示例

    getdate函数 PHP getdate()函数 (PHP getdate() function) getdate() function is used to get the local date/ ...

  4. 安卓log.e函数打印示例_log1p()函数以及C ++中的示例

    安卓log.e函数打印示例 C ++ log1p()函数 (C++ log1p() function) log1p() function is a library function of cmath ...

  5. gettimeofday_PHP gettimeofday()函数与示例

    gettimeofday PHP gettimeofday()函数 (PHP gettimeofday() function) gettimeofday() function is used to g ...

  6. dir函数_PHP dir()函数与示例

    dir函数 PHP dir()函数 (PHP dir() function) dir() function is an instance of the directory class, it is u ...

  7. PHP rewinddir()函数与示例

    PHP rewinddir()函数 (PHP rewinddir() function) rewinddir() function is used to rewind/reset the direct ...

  8. stl swap函数_C ++ STL | vector :: swap()函数与示例

    stl swap函数 C ++ STL vector :: swap()函数 (C++ STL vector::swap() function) vector::swap() function is ...

  9. C#回调函数应用示例,形象比喻方法助理解

    C#回调函数应用示例,形象比喻方法助理解,整理了一个简单的例子来说明回调函数的用法: namespace CallBackFunction {     class Program     {      ...

最新文章

  1. 训练损失越来越大_无需contrastive学习,微软亚研提基于实例分类无监督预训练方法...
  2. 与variant有关的几个FUNCTION
  3. Android 高级Drawable资源---复合Drawable----层Drawable
  4. 测试方案和测试计划的区别
  5. HTML参考系列(5)-表格标签
  6. java8(2)--- Stream API
  7. HDU 4371 Alice and Bob
  8. 【数据库】SQLITE3 加密3
  9. 回顾:HTTP/HTTPS/对称加密/非对称加密/session/cookie/token
  10. 英语发音之音标4---长元音法()
  11. [从头学数学] 第203节 坐标系与参数方程
  12. c语言五子棋人工智能算法,五子棋人工智能算法实现研究,优化五子棋智能算法的思路...
  13. Kinect for Unity3d----KinectManager
  14. java程序开启远程调试、断点功能
  15. Verilog轮询仲裁器设计——Round Robin Arbiter
  16. 计算机辅助训练对吞咽障碍,吞咽障碍的六大家庭训练方法
  17. 百度SEO逆推技术软件下载,引蜘蛛秒收录
  18. 分享实录 | 技术更迭视角下的游戏语音新玩法
  19. 认证服务:整合短信验证码
  20. apache benchmark(ab) 进行压测

热门文章

  1. 职业技术人士学习捷径最快的网站
  2. java编程一般类抽象类的定义,Java编程基础抽象类
  3. linux 提升cpu权限,CPUlimit有效防止Linux系统CPU过载
  4. 发现2017年最好的CSS框架
  5. zabbix监控docker容器
  6. 封装axios的接口请求数据方法
  7. SpriteKit在复制节点时留了一个巨坑给开发者,需要开发者手动把复制节点的isPaused设置为false...
  8. Pointcut is not well-formed: expecting #39;name pattern#39; at character position 36
  9. 把txt文件中的json字符串写到plist文件中
  10. (ios7) 解决代码布局View, ios7 中 subView 高度增加StatusBar20dp的问题,保证Ios6,ios7代码一致...