Selection Sort in PHP/Javascript