<?php
// Recursive version:
function quicksort($seq) {
if(!count($seq)) return $seq;
$pivot= $seq[0];
$low = $high = array();
$length = count($seq);
for($i=1; $i < $length; $i++) {
if($seq[$i] <= $pivot) {
$low [] = $seq[$i];
} else {
$high[] = $seq[$i];
}
}
return array_merge(quicksort($low), array($pivot), quicksort($high));
}
//Let's try some examples
$myarr = array(25,5,3,4,17,1,88,8);
$final = quicksort($myarr);
print_r($final);
$final = quicksort($final);
print_r($final);
$strarray = array("mark","wes","mj","bruce","ming","lance","vince");
var_dump(quicksort($strarray));
?>
Im new to php and i was wondering how can i make this loop more than 100 times. I have an array 2500 int element that i need to do a quick sort on and display the results, however after 100 element it start giving the loop maximum error..........any idea?
Yes. Use some of the built-in sort functions. For instance: sort()
. Check the Sorting Arrays
manual to see the complete list.