首页 > 编程语言 >php 二维数组排序

php 二维数组排序

时间:2023-06-25 16:37:45浏览次数:51  
标签:排序 name int age 二维 array php string

主要通过 array_multisort 函数来进行排序

php 二维数组排序_php

<?php
//原数组
$arr = [
    ["name"=>"小明","age"=>18],
    ["name"=>"小红","age"=>7],
    ["name"=>"小刚","age"=>52],
    ["name"=>"小亮","age"=>33],
];
//将元素组的需排序的字段获取出来
$column = array_column($arr,"age");

//进行排序
array_multisort($column,SORT_DESC,$arr);
var_dump($arr);

结果如下


array(4) { [0]=> array(2) { ["name"]=> string(6) "小刚" ["age"]=> int(52) } [1]=> array(2) { ["name"]=> string(6) "小亮" ["age"]=> int(33) } [2]=> array(2) { ["name"]=> string(6) "小明" ["age"]=> int(18) } [3]=> array(2) { ["name"]=> string(6) "小红" ["age"]=> int(7) } }


标签:排序,name,int,age,二维,array,php,string
From: https://blog.51cto.com/u_15668841/6546678

相关文章

  • 在idea中debug php程序
    在php.ini中配置debug[ioncube]zend_extension=php_ioncube.dll[XDebug]zend_extension="D:\BtSoft\php\74\php_xdebug-3.1.4-7.4-vc15-nts-x86_64.dll"xdebug.profiler_append=1xdebug.profiler_enable=1xdebug.auto_trace=Onxdebug.profiler_enable......
  • Java 插入排序
    publicstaticint[]insertSort(int[]nums){for(inti=1,len=nums.length;i<len;i++){intcurrent=nums[i];intj=i-1;for(;j>=0&&current<nums[j];j--)num......
  • PHP8开启JIT
    JIT时php8的重要功能之一,可以极大的提高性能;JIT编译器集成在了Opcache插件中,仅在启动Opcache插件才有效Opcache将PHP脚本编译后的字节码存储到内存中,以避免每次执行脚本时重新解析和编译,从而提高PHP应用程序的性能和响应速度。 Opcache开启:编辑php.ini文件,将zend_exten......
  • C语言中将二维数组作为函数参数来传递
    C语言中经常需要通过函数传递二维数组,有三种方法可以实现,如下:方法一,形参给出第二维的长度#include<stdio.h>voidfunc(intn,charstr[][5]){inti;for(i=0;i<n;i++)printf("/nstr[%d]=%s/n",i,str[i]);}voidmain(){char*p[3];charstr[]......
  • PHP中的文件操作
    $dirName='D:\WXWork\1688856202390297\Cache\File\2023-06\汽配城图片\汽配城图片';$temp_list=scandir($dirName);foreach($temp_listas$file){//排除根目录if($file!=".."&&$file!=&qu......
  • Liunx下对php内核的调试
    0x01前言主要是对上一篇文章中php_again这道题的补充。0x02下载php源码cd/usr/localwgethttps://www.php.net/distributions/php-8.2.2.tar.gztar-zxvfphp-8.2.2.tar.gz&&cdphp-8.2.20x03编译注意带enable-debugapt-getinstallbuild-essentialautoconfautomak......
  • 【js学习笔记五】数组双重去重的方式四先排序在对比
     目录前言导语 代码部分运行结果总结前言   我是歌谣我有个兄弟巅峰的时候排名c站总榜19叫前端小歌谣曾经我花了三年的时间创作了他现在我要用五年的时间超越他今天又是接近兄弟的一天人生难免坎坷大不了从头再来歌谣的意志是永恒的放弃很容易但是坚持一定很酷导语......
  • PHP用Swoole的WebSocket功能编写聊天室Demo
    前提:linux环境下PHP有可用的Swoole扩展。9501端口可访问。后端<?phpclassHelper{/***@function将数组中的null值转化为空字符串*@param$arrarray要转化的数组*@returnarray*@othervoid*/publicstaticfuncti......
  • c# 基于wechat_qrcode opencv插件,网络二维码图片批量识别(一)
     一、基本概念  微信开源了其二维码的解码功能,并贡献给OpenCV社区。其开源的wechat_qrcode项目被收录到OpenCVcontrib项目中。从OpenCV4.5.2版本开始,就可以直接使用。该项目github地址: https://github.com/opencv/opencv_contrib/tree/master/modules/wechat_......
  • 使用PhpAmqpLib常用的2种连接rabbitmq的方式
    #connecttoAMQPbrokeratexample.comusePhpAmqpLib\Connection\AMQPStreamConnection;$amqp=newAMQPStreamConnection('example.com',5672,'user','pwd','/host');#SSLorsecureconnectionusephpAmqpLib\Connection......