Check this one , this one is more efficient
$array=array('2','4','8','5','1','7','6','9','10','3');
for($i=1;$i< count($array);$i++)
{
for($j=$i;$j>0;$j--)
{
if($array[$j] < $array[$j-1])
{
$tmp = $array[$j];
$array[$j] = $array[$j-1];
$array[$j-1] = $tmp ;
}
}
}
echo "";
print_r($array);