Home > Backend Development > PHP Tutorial > Simple implementation of bubble sort in PHP

Simple implementation of bubble sort in PHP

WBOY
Release: 2016-07-25 09:06:02
Original
1144 people have browsed it
When I was learning PHP, I didn’t dare to get close to the algorithm. I was just afraid of disturbing my thoughts. Looking back now, it was really just that. hey-hey! Have any of you encountered such a situation? ha
  1. #Bubble sorting method
  2. $arr = array(12,45,89,3,24,55,223,76,22,11,89,2,4,5,28,112,20,434, 23,65,65,765,6,8,23,5,33,553,45,423,64,77,84,23);
  3. $tmp;
  4. for($i=0;$i for($j=0;$j if($arr[$j] > $arr[$j+1]) {
  5. $tmp = $arr[$j];
  6. $arr[$j] = $arr[$j+1];
  7. $arr[$j+1] = $tmp;
  8. }
  9. }
  10. }
  11. print_r($arr);
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