Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
function sort(array $data)
{
$count_elements = count($data);
$iterations = $count_elements - 1;
for ($i=0; $i < $count_elements; $i++) {
$changes = false;
for ($j=0; $j < $iterations; $j++) {
if ($data[$j] > $data[($j + 1)]) {
$changes = true;
list($data[$j], $data[($j + 1)]) = array($data[($j + 1)], $data[$j]);
}
}
$iterations--;
if (!$changes) {
return $data;
}
}
return $data;
}
var_dump(sort([2,3,1,2,4,5]));