selection sort - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of selection sort.php

  1. <?php
  2. $values= array(1,4,10,3,30,14,5);
  3. $size = count($values);
  4.  
  5. for($i=0;$i<=$size;$i++)
  6.   {
  7.         for($j=$i+1;$j<=$size;$j++)
  8.        {
  9.         if($values[$j] < $values[$i])
  10.         {
  11.             $min = $values[$j];
  12.             $values[$j] = $values[$i];
  13.             $values[$i] = $min;
  14.         }    
  15.        }
  16.     print $values[$i]."\n";
  17.       
  18.   }
  19.    
  20.    
  21.    
  22.    
  23.    
File Description
  • selection sort
  • PHP Code
  • 11 Jan-2021
  • 386 Bytes
You can Share it: