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.  
  6. function display($array) {
  7. $total = count($array);
  8.         foreach($array as $key => $valeur) {
  9.                 if($key == ($total - 1))
  10.                 {
  11.                         echo("$valeur");
  12.                 }
  13.                 else
  14.                 {
  15.                         echo("$valeur, ");
  16.                 }
  17.         }
  18. }
  19.  
  20. echo("valeur non triee : ");
  21. display($values);
  22. echo ("<br>");
  23. echo ("valeur tiree : ");
  24. for($i=0;$i<=$size;$i++)
  25.   {
  26.         for($j=$i+1;$j<=$size;$j++)
  27.        {
  28.         if($values[$j] < $values[$i])
  29.         {
  30.             $min = $values[$j];
  31.             $values[$j] = $values[$i];
  32.             $values[$i] = $min;
  33.         }    
  34.        }
  35.     echo(", $values[$i]");
  36.       
  37.   }
  38. echo ("<br>");   
  39.    
  40.    
  41.    
  42.    
File Description
  • selection sort
  • PHP Code
  • 11 Jan-2021
  • 653 Bytes
You can Share it: