$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;
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.