Sort the array by the specified KEY value

WBOY
Release: 2016-07-25 09:01:26
Original
1029 people have browsed it

  1. function array_sort($arr,$keys,$orderby='asc'){
  2. $keysvalue = $new_array = array();
  3. foreach ($arr as $k=>$v){
  4. $keysvalue[$k] = $v[$keys];
  5. }
  6. if($orderby== 'asc'){
  7. asort($keysvalue);
  8. }else{
  9. arsort($keysvalue);
  10. }
  11. reset($keysvalue);
  12. foreach ($keysvalue as $k=>$v){
  13. $new_array[] = $arr[$k];
  14. }
  15. return $new_array;
  16. }
复制代码


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