Home  >  Article  >  Backend Development  >  Sort the array by the specified KEY value

Sort the array by the specified KEY value

WBOY
WBOYOriginal
2016-07-25 09:01:26998browse

  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. }
复制代码


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