Home  >  Article  >  Backend Development  >  Sorting of multidimensional arrays in php

Sorting of multidimensional arrays in php

WBOY
WBOYOriginal
2016-08-08 09:32:13994browse
$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;
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.

Statement:
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