Home >Backend Development >PHP Tutorial >A simple method to implement quick sorting in php_PHP tutorial
This article describes an example of a simple way to implement quick sorting in PHP. Share it with everyone for your reference. The specific implementation method is as follows:
4 11 12 |
function quicksort($seq) { if(!count($seq)) return $seq; $k = $seq[0]; $x = $y = array(); for($i=count($seq); --$i;) { if($seq[$i] <= $k) { $x[] = $seq[$i]; } else { $y[] = $seq[$i]; } } return array_merge(quicksort($x),array($k),quicksort($y)); } |