Home > Backend Development > PHP Tutorial > How to sort a two-dimensional associative array in PHP according to one of its fields

How to sort a two-dimensional associative array in PHP according to one of its fields

墨辰丷
Release: 2023-03-27 18:48:01
Original
1593 people have browsed it

This article mainly introduces the example code of PHP two-dimensional associative array sorting according to one of the fields. It is very good and has reference value. Friends in need can refer to

How to use two-dimensional associative arrays in PHP To sort according to one of the fields, the following code sorts the two-dimensional associative array $array according to the $orderby field:

function wpjam_array_multisort($array, $orderby, $order = SORT_ASC, $sort_flags = SORT_NUMERIC){
 $refer = array();
 foreach ($array as $key => $value) {
 $refer[$key] = $value[$orderby];
 }
 array_multisort($refer, $order, $sort_flags, $array);
 return $array;
}
Copy after login

The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

bind_param() function usage analysis in php

PHPAnalysis of the method of creating an empty object using new StdClass()

ThinkPHP 3.2.2 Methods to implement transaction operations

The above is the detailed content of How to sort a two-dimensional associative array in PHP according to one of its fields. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template