php arsort_PHP arsort()函数与示例

php arsort

PHP arsort()函数 (PHP arsort() function)

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

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

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

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

Syntax:

句法:

    arsort(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
    (    
        [prem] => 27 
        [manju] => 25
        [radib] => 21
        [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...
    
    arsort($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
(    
    [prem] => 27 
    [manju] => 25
    [radib] => 21
    [amit] => 21 
    [abhi] => 20 
) 


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

php arsort

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值