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. flask基础(上篇)
  2. js进阶 12-8 如何知道鼠标和键盘当前操作的是哪个键
  3. IOS 粒子发射器,雪花落下、创建火焰、河流、蒸汽的动画效果源代码
  4. python必刷面试_Python面试必刷题系列(5)
  5. [Leetcode] 第306题 累加数
  6. 【C语言进阶深度学习记录】九 C语言中const的详细分析
  7. [你必须知道的.NET]第二十回:学习方法论
  8. Emlog明月浩空主题模板V2.7分享
  9. 微信收费事件背后被广泛忽略的技术细节
  10. CMakeFiles/species.inc.dir/build.make:57: recipe for target 'CMakeFiles/species.inc' failed
  11. eclipse 启动 tomcat : Multiple Contexts have a path of /SOAProject
  12. Oracle笔记整理
  13. atitit.条形码的原理与生成总结java Barcode4j barcode o5
  14. android 反编译 dex2jar,Android反编译教程:apktool,dex2jar的使用
  15. 【Linux】网络篇三--UDP编程
  16. 简单两个矩阵如何用计算机运算,矩阵运算-如何用卡西欧fx-82es计算器计算矩阵和 – 手机爱问...
  17. 快手短视频广告投放是怎么收费的 快手信息流广告收费标准
  18. MetaMask新版本新增获取并修改用户剪切板内容权限
  19. win10小喇叭出现红叉,解决办法(转)
  20. java中如果int类型超出了它的范围

热门文章

  1. mysql、oracle知识点总结
  2. 一段js实现复制文本内容到剪切板
  3. CSS 水平垂直居中
  4. Codeforces 765F. Souvenirs
  5. 排序算法之(7)——堆排序
  6. Array的用法总结-swift
  7. mxnet系列教程之1-第一个例子
  8. xml配置文件推荐方式
  9. 使用MJRefresh自定义下拉刷新,上拉加载动画
  10. Fix “Windows cannot access the specified device path or file” Error