<?php function quick_sort(array& $array,$low,$high){ if($low >= $high){ return $array;//递归出口,数组的最高位下标小于数组最低位下标 } $i = $low; $j = $high+1; //数组切分循环 $v = $array[$low];//切分元素 while(true){//循环查找 while($array[--$j] >= $v)if($j == $low)break;//从右往左查找第一个比$v小的元素 while($array[++$i] <= $v)if($i == $high)break;//从左往右查找第一个比$v大的元素 if($i >= $j)break;//指针相遇 $tmp = $array[$j]; $array[$j] = $array[$i]; $array[$i] = $tmp; //元素位置交换 } $array[$low] = $array[$j]; $array[$j]= $v;//将切分元素放入相应位置 quick_sort($array,$low,$j-1); quick_sort($array,$j+1,$high); //递归调用 } $array = array('6','1','3','2','5','6','5','10','234','1'); $high = count($array); quick_sort($array,0,$high-1); var_dump($array);