Home > Backend Development > PHP Tutorial > Sorting of multidimensional arrays in php

Sorting of multidimensional arrays in php

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-08 09:32:13
Original
1112 people have browsed it
$aProduct = array(
    0=> array('goods_id' => 1,'name' =>'iPhone 4','is_group' =>4),
    1=> array('goods_id' => 2,'name' =>'iPhone 4s','is_group' =>6),
    2=> array('goods_id' => 3,'name' =>'iPhone 5','is_group' =>1),
    3=> array('goods_id' => 4,'name' =>'iPhone 5s','is_group' =>1)
);
function arraySort($multi_array,$sort_key,$sort=SORT_ASC){
    if(is_array($multi_array)){
        foreach ($multi_array as $row_array){
            if(is_array($row_array)){
                $key_array[] = $row_array[$sort_key];
            }else{
                return false;
            }
        }
    }else{
        return false;
    }
    array_multisort($key_array,$sort,$multi_array);
    return $multi_array;
}
print_r(arraySort($aProduct,'is_group',SORT_DESC));exit;
Copy after login
http://www.ruesin.com/php/array_multisort-12.html

The above introduces the sorting of multi-dimensional arrays in PHP, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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
Latest Issues
How to create an array within an array?
From 1970-01-01 08:00:00
0
0
0
php array
From 1970-01-01 08:00:00
0
0
0
Array to array
From 1970-01-01 08:00:00
0
0
0
php array rotation
From 1970-01-01 08:00:00
0
0
0
array
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template