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