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

What are the PHP sorting functions?

WBOY
Release: 2016-07-25 08:53:26
Original
1001 people have browsed it
  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


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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template