Trying to sort PHP array in ascending order but loosing grip
<?php
$array = [4,5,63,2,1,66,43];
$count = count($array);
$counter = 0;
for ($i=0; $i < count($array); $i++) {
if($counter > 100)
break;
if($array[$i] < $array[$i + 1]) {
continue;
} else {
$now_i = $array[$i];
unset($array[$i]);
$array[] = $now_i;
$array = array_values($array);
$i = 0;
}
print_r($array);
$counter++;
}
// End up with this array
Array
(
[0] => 4
[1] => 1
[2] => 2
[3] => 5
[4] => 43
[5] => 63
[6] => 66
)
I will appreciate if some champ would fix this as i spend 4 hours thinking whats going wrong.
Thanks