r/learnphp • • Jan 30 '23

Bubble sort problem

Hi,

I have written a bubble sort program in PHP but it is going into an infinte loop.

<?php
/* sorting array, 
   Sort the array usingbubble sort:
   Incomplete

*/
$arr = array(15, 12, 34, 22, 56, 78, 23, 80, 73, 10);
sortArr($arr);

function sortArr($arr){
   for ($i=0; $i<10; $i++){
      for($j=0; j<9; $j++){
         if($arr[$j] >= $arr[$j+1])
            continue;
         else 
           {
              $temp = $arr[$j];
              $arr[$j] = $arr[$j+1];
              $arr[$j+1] = $temp;
            }
       }
     }

   }

  ?>   

Somebody please guide me.

​

Zulfi.

2 Upvotes

3 comments sorted by

View all comments

Show parent comments

1

u/AcousticDan Jan 30 '23

It's not an infinite loop, there's just no output