Sort An Array In PHP Without Using Inbuilt/Predefined Function.

<?php
$array = array(9, 2, 18, 34, 3, 10, 15);
// get the size of array
$count = count($array);
for ($i = 0; $i < $count; $i++) {
 for ($j = $i + 1; $j < $count; $j++) {
   if ($array[$i] > $array[$j]) {
       $temp = $array[$i];
       $array[$i] = $array[$j];
       $array[$j] = $temp;
    }
  }
}
print_r($array);
Advertisements