PHP implements multidimensional array sorting function sharing for specified fields

Source: Internet
Author: User
Tags array sort php code sort

This article mainly introduces the PHP implementation of the specified field of multidimensional array sorting function sharing, this article shares a section of the PHP specified field of multidimensional array sorting method code, this code can be implemented according to the field of the array of groups to sort, the need for friends can refer to the

PHP array sorting can be implemented in the Array_multisort method, but if it is a multidimensional array, and we want to specify a field in the array to sort, then we need to write our own method implementation. This article shares the code for a multidimensional array sort method for a PHP-specified field that can be sorted by the array of field fields.

The code is as follows:
Function Sortarrbyfield (& $array, $field, $desc = False) {
$FIELDARR = Array ();
foreach ($array as $k => $v) {
$FIELDARR [$k] = $v [$field];
$sort = $desc = = False? Sort_asc:sort_desc;
Array_multisort ($FIELDARR, $sort, $array);
The above is the PHP specified field of multidimensional array sorting method, I hope this section of PHP code to bring you help.
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.