Home >Backend Development >PHP Tutorial >PHP method to implement array sorting by specified KEY, PHP array key sorting_PHP tutorial

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

WBOY
WBOYOriginal
2016-07-13 09:59:16979browse

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;
}

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