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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 09:59:16
Original
1010 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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template