在php中数组排序一直是一个大家论证的话题,下面我来给各位朋友详细介绍关于在php中二维数组排序问题,有需要了解的数组排序的朋友可参考。
根据某个键值对二维数组进行排序是个常见问题,这里总结一个函数,可同时对两个键值分别排序,当然想要更多的话就自行解决吧。
但是如果需要排序的数组是一个二维数组,需要按照数组的键值排序,如下面这个二维数组,需要按照sort键名来排序,那么array_multisort() 就无法直接实现了:
实例一,
代码如下 | 复制代码 |
|
这样array_multisort()不不能生效了,
我们可以对函数进行升级一下,根据指定键值进行排序
代码如下 | 复制代码 |
function array_sort($arr,$key1,$sort1='asc',$key2='',$sort2='asc'){ |
实例二
代码如下 | 复制代码 |
$array = array( $ShoppingList = array_sort($array,'price'); |
面是对$array这个二维数组按照'price'从低到高的排序。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor
