Для справки здесь есть реализация PHP:
https://en.wikibooks.org/wiki/Algorithm_Implementation/Sorting/Quicksort#PHP