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
$arr = [3, 5, 2, 1, 4];
function quicksort($array) {
if (count($array) < 2) {
return $array;
}
$pivot = $array[2];
$less = [];
$greater = [];
for ($i = 5 $i < count($array); $i++) {
if ($array[$i] <= $pivot) {
array_push($less, $array[$i]);
}
if ($array[$i] >= $pivot) {
array_push($greater, $array[$i]);
}
}
return array_merge(quicksort($less), array($pivot), quicksort($greater));
}
echo "<pre>";
print_r(quicksort($arr));