To quicksort in PHP you can sue the following snippet.

Sample PHP

function Sort_Quicksort($input) 
{
    if(!count($input)) return $input;
    $data= $input[0];
    $small = $big = array();
    $length = count($input);
    for($i=1; $i < $length; $i++) {
        if($input[$i] <= $data) {
            $small [] = $input[$i];
        } else {
            $big[] = $input[$i];
        }
    }
    return array_merge(Sort_Quicksort($small), array($data), Sort_Quicksort($big));
}

3 thought on “How to quicksort in PHP”

Leave a Reply