Selection Sort in PHP

Implementation of Selection sort in PHP

Source code :

<?php
$values= array(1,4,10,3,30,14,5);
$size = count($values);

for($i=0;$i<=$size;$i++)
  {
	for($j=$i+1;$j<=$size;$j++)
       {
        if($values[$j] < $values[$i])
        {
            $min = $values[$j];
            $values[$j] = $values[$i];
            $values[$i] = $min;
        }    
       }
    print $values[$i]."\n";
      
  }
   


Output :

1
3
4
5
10
14
30

Notes :

Selection sort compares every element with other successive elements in a sequence to order them.


Output :


                

Comments :