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.
Result of php executing
Full code of selection sort.php
- <?php
- $debut = microtime(true);
- $values= array(1,4,10,3,30,14,5);
- $size = count($values);
- function display($array) {
- $total = count($array);
- foreach($array as $key => $valeur) {
- if($key == ($total - 1))
- {
- echo("$valeur");
- }
- else
- {
- echo("$valeur, ");
- }
- }
- }
- echo("valeur non triee : ");
- display($values);
- echo ("<br>");
- echo ("valeur tiree : ");
- 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;
- }
- }
- echo(", $values[$i]");
- }
- $fin = microtime(true);
- echo ("<br>");
- $time = $fin - $debut;
- echo ("temps du programme : $time secondes");