diff --git a/PHP/Sorting/QuickSort.php b/PHP/Sorting/QuickSort.php new file mode 100644 index 0000000..527c6ca --- /dev/null +++ b/PHP/Sorting/QuickSort.php @@ -0,0 +1,23 @@ + $x <= $pivot); + $right = array_filter(array_slice($array, 1), fn($x) => $x > $pivot); + + // Recursively apply quicksort to left and right arrays, then merge + return array_merge(quickSort($left), [$pivot], quickSort($right)); +} + +// Example usage: +$array = [3, 6, 8, 10, 1, 2, 1]; +$sortedArray = quickSort($array); +print_r($sortedArray);