To perform this task, we canuse the following method: compare each element of the array, and the
larger of the two compared move to the right side, thus sorting array in
ascending order. Below is the code, which is based on this method.
<?php
$input= array(0.1,77,0.5,6.2,6,2,4);
for($i=0;$i<count($input)-1;$i++)
for($c=0;$c<count($input)-1;$c++){
if($input[$c]>$input[$c+1]){
$t=$input[$c];
$input[$c]=$input[$c+1];
$input[$c+1]=$t;
}
}
print_r($input);
?>
Comments
Leave a comment