Friday, 29 April 2016

Sorting Array without sorting function in PHP

<?php

$array=array(8,4,9,11,2);

for($i=0;$i < count($array);$i++)
{
    for($j=0;$j < $i;$j++)
    {
        if($array[$i] < $array[$j])
        {
            $temp=$array[$i];
            $array[$i]=$array[$j];
            $array[$j]=$temp;
        }
    }
}
print_r($array);

?>

No comments:

Post a Comment