<?php
function swap(&$array, $i, $j) {
$temp = $array[$i];
$array[$i] = $array[$j];
$array[$j] = $temp;
}
function indexOfMin(&$array, $startIndex) {
$minValue = $array[$startIndex];
$minIndex = $startIndex;
for ($i = $minIndex + 1; $i < count($array); $i++) {
if ($array[$i] < $minValue) {
$minValue = $array[$i];
$minIndex = $i;
}
}
return $minIndex;
}
function selectSort(&$array) {
for ($i = 0; $i < count($array); $i++) {
$j = indexOfMin($array, $i);
swap($array, $i, $j);
}
}
$array = [4,2,5,3,1];
print_r($array);
selectSort($array);
print_r($array);
To embed this project on your website, copy the following code and paste it into your website's HTML: