[code=php]<?php

/*
 *@description: implements quicksort algorithm
*/

function QuickSort($arr) {
	$arrLTP = $arrGTP = array(); // array less/greater than pivot
	$len = sizeof($arr);
	$pivot = 0; // we choose pivot as first element of array
	if ($len >= 1) {
		for ($i = 1; $i < $len; $i++) {
			if ($arr[$i] > $arr[$pivot]) {
				$arrGTP[] = $arr[$i];
			} else {
				$arrLTP[] = $arr[$i];
			}
		}
		if (!empty($arrGTP)) {
			$arrGTP = QuickSort($arrGTP);
		}
		if (!empty($arrLTP)) {
			$arrLTP = QuickSort($arrLTP);
		}
		$arrSorted = array_merge($arrLTP, array($arr[$pivot]), $arrGTP);
		
		return $arrSorted;
	} else {
		return array();
	}
}

/*
$quick = array(5,1,2,5,4,8,1,6,84,3,8,84,2,8);
$quicksort = Quicksort($quick);
foreach($quicksort as $v) {
	echo $v . " ";
}
*/
?>