PHP method to implement array sorting by specified KEY, PHP array key sorting_PHP tutorial

WBOY
Release: 2016-07-13 09:59:16
Original
953 people have browsed it

php method to implement array sorting by specified KEY, php array key sorting

This article describes the example of php method to implement array sorting by specified KEY. Share it with everyone for your reference. The specific implementation method is as follows:

function array_sort($arr,$keys,$orderby='asc'){
  $keysvalue = $new_array = array();
  foreach ($arr as $k=>$v){
    $keysvalue[$k] = $v[$keys];
  }
  if($orderby== 'asc'){
    asort($keysvalue);
  }else{
    arsort($keysvalue);
  }
  reset($keysvalue);
  foreach ($keysvalue as $k=>$v){
    $new_array[] = $arr[$k];
  }
  return $new_array;
}
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/976020.htmlTechArticlephp method to implement array sorting by specified KEY, php array key sorting This article describes the example of php implementing array by specified KEY Sorting method. Share it with everyone for your reference. The specific implementation methods are as follows...
Related labels:
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