# Answer to Question #26252 in AJAX | JavaScript | HTML | PHP for shahbaz

Question #26252

how we can sort and asort digit without using default function of php....?

Expert's answer

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);

?>

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);

?>

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment