**In this tutorial I show how to implement a Quicksort algorithm in PHP.**

**Code:**

```
<?php
$arr = generateArr();
print("UNSORTED ARRAY:<br />");
print_r($arr);
print("<br />SORTED ARRAY:<br />");
quickSort($arr, 0, sizeof($arr) - 1);
print_r($arr);
function generateArr()
{
$a = [];
for ($i = 0; $i < 10; $i++) {
$a[] = rand(0, 100);
}
return $a;
}
function quickSort(&$array, $lowOrig, $highOrig)
{
if (sizeof($array) < 2) {
return;
}
$pivot = $array[($lowOrig + $highOrig) / 2];
$low = $lowOrig;
$high = $highOrig;
while ($low <= $high) {
while ($array[$low] < $pivot) {
$low++;
}
while ($array[$high] > $pivot) {
$high--;
}
if ($low <= $high) {
// Swap their values
$temp = $array[$low];
$array[$low] = $array[$high];
$array[$high] = $temp;
$low++;
$high--;
}
}
if ($lowOrig < $high) {
quickSort($array, $lowOrig, $high);
}
if ($low < $highOrig) {
quickSort($array, $low, $highOrig);
}
}
```