awk asort_PHP asort()函数与示例

news/2024/7/19 13:33:48 标签: 字符串, python, php, java, js

awk asort

PHP asort()函数 (PHP asort() function)

asort() function is used to sort an associative array in ascending 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.

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

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

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

Syntax:

句法:

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

PHP code:

PHP代码:

<?php    
    $person = array(
        "radib" => 21,
        "amit" => 21,
        "abhi" => 20,
        "prem" => 27,
        "manju" => 25
        );

    print ("unsorted array...\n");
    print_r ($person);
    //sorting...
    
    asort($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 
(     
    [abhi] => 20 
    [radib] => 21
    [amit] => 21 
    [manju] => 25
    [prem] => 27 
)  


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

awk asort


http://www.niftyadmin.cn/n/1254060.html

相关文章

linux 链接 got plt,Linux动态连接原理 GOT PLT表详解

转载逆风飞扬的文章&#xff0c;有时间有需要认真研究。Linux动态连接原理 GOT PLT表详解 注意&#xff1a; 以下所用的连接器是指&#xff0c;ld&#xff0c; 而加载器是指ld-linux.so; 1&#xff0c; GOT表&#xff1b; GOT(Global Offset Table)表中每一项都是本运行模块要…

洛谷 P1202 模拟 - 黑色星期五 Friday the Thirteenth

【题目描述】 13号又是一个星期五。13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序&#xff0c;要求计算每个月的十三号落在周一到周日的次数。给出N年的一个周期&#xff0c;要求计算1900年1月1日至1900N-1年12月31日中十三号落在周一到周日的次数&#xff0c;N为…

scala交换数组相邻两位_C ++程序交换相邻位

scala交换数组相邻两位Problem statement: C program to swap all odd bits with even bits (swap adjacent bits). Every even positiC program to swap all odd bits with even bits (swap adjacent bits). Every even position bit is swapped with an adjacent bit on the …

大数相加c 语言,大数相加

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼#include #include /**** 定义双向节点* 数据区为一个整型数字***/struct Node {int number;//数据区&#xff0c;仅一个数字&#xff0c;保存一位数字struct Node * next;struct Node * prev;};typedef struct Node Node;/*** 创建…

不懂的名词

中间件转载于:https://www.cnblogs.com/givemeanorange/p/10076395.html

ibps_IBPS的完整形式是什么?

ibpsIBPS&#xff1a;银行人员选拔研究所 (IBPS: Institute of Banking Personnel Selection) IBPS is an abbreviation of the Institute of Banking Personnel Selection. It is a self-governing recruitment organization which works towards the process of encouraging …

js002---- 标准内置对象

1. js全局的对象&#xff08;全局作用域里的对象&#xff0c;而不是全局对象&#xff09;&#xff0c; 或者叫标准内置对象 2&#xff0c; 全局对象 是一个Global类的对象。 标准内置对象的分类&#xff1a; 1。 值属性 infinity NaN undefined null字…

c 语言编程软件打开文件,VC WinExec打开指定程序或者文件的方法

⑴ 函数原型&#xff1a;UINT Win Exec(LPCSTR lpCmdLine, UINT uCmdShow);⑵ 参数&#xff1a;lpCmdLine&#xff1a;指向一个空结束的字符串&#xff0c;串中包含将要执行的应用程序的命令行(文件名加上可选参数)。uCmdShow&#xff1a;定义Windows应用程序的窗口如何显示&…