[Solved] Sorting arrays manually in php without using sort() [closed]


here is the solution using bubble sort

<?php
$item = array(2, 1, 4,3,5,6);
$item_length = count($item);
for ($counter = 0; $counter < $item_length-1; $counter++) {
  for ($counter1 = 0; $counter1 < $item_length-1; $counter1++) {
    if ($item[$counter1] > $item[$counter1 + 1]) {
       $temp=$item[$counter1];
       $item[$counter1]=$item[$counter1+1];
       $item[$counter1+1]=$temp;
       }
    }
 }

//you can print the array using loop
print_r($item);
?> 

1

solved Sorting arrays manually in php without using sort() [closed]