PHP two-dimensional array sorting custom function

WBOY
Release: 2016-07-25 08:52:21
Original
964 people have browsed it
A custom function for sorting two-dimensional arrays in PHP. Please share it with friends who find it useful.

The code is as follows:

<?php
/**
* func: array_sort
* desc: php二维数组排序
* edit: bbs.it-home.org
*/
function array_sort($arr,$keys,$type='asc'){
   $keysvalue = $new_array = array();
       foreach ($arr as $k=>$v){
       $keysvalue[$k] = $v[$keys];
   }
   if($type == 'asc'){
       asort($keysvalue);
   }else{
       arsort($keysvalue);
   }
   reset($keysvalue);
       foreach ($keysvalue as $k=>$v){
       $new_array[$k] = $arr[$k];
   }
   return $new_array;
} 
?>
Copy after login

>>> For more information, please view the complete list of php array sorting methods



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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!