Home >Backend Development >PHP Tutorial >What are the PHP sorting functions?

What are the PHP sorting functions?

WBOY
WBOYOriginal
2016-07-25 08:53:261007browse
  1. //php sorting function example
  2. function array_sort($arr,$keys,$type='asc')
  3. {
  4. echo 'Start sorting...'.' $keysvalue = $new_array = array();
  5. foreach ($arr as $k=>$v)
  6. {
  7. $keysvalue[$k] = $v[$keys];
  8. }
  9. if( $type == 'asc')
  10. {
  11. asort($keysvalue);
  12. }
  13. else
  14. {
  15. arsort($keysvalue);
  16. }
  17. reset($keysvalue);
  18. foreach ($keysvalue as $k=> $v)
  19. {
  20. $new_array[$k] = $arr[$k];
  21. }
  22. echo 'End of sorting...'.'
    ';
  23. return $new_array;
  24. }
Copy code


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