note 11164 deleted from function.sort by derick

From: Date: Wed, 31 Aug 2005 10:35:41 +0000
Subject: note 11164 deleted from function.sort by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-94487@lists.php.net to get a copy of this message
Note Submitter: CK1 at wwwtech dot de ---- Hi, sorry for spamming ;) But I forgot the ASC DESC feature. Just change the function to the following: function qsort_multiarray($array,$num = 0,$order = "ASC",$left = 0,$right = -1) { if($right == -1) { $right = count($array) - 1; } $links = $left; $rechts = $right; $mitte = $array[($left + $right) / 2][$num]; if($rechts > $links) { do { if($order == "ASC") { while($array[$links][$num]<$mitte) $links++; while($array[$rechts][$num]>$mitte) $rechts--; } else { while($array[$links][$num]>$mitte) $links++; while($array[$rechts][$num]<$mitte) $rechts--; } if($links <= $rechts) { $tmp = $array[$links]; $array[$links++] = $array[$rechts]; $array[$rechts--] = $tmp; } } while($links <= $rechts); $array = qsort_multiarray($array,$num,$order,$left, $rechts); $array = qsort_multiarray($array,$num,$order,$links,$right); } return $array; } Call the function like this: $array = qsort_multiarray(array $array,int $n,string $order,int $left,int $right); $array is the array which should be sorted, int $n is the index of the sort criterium, $order is "ASC" or "DESC" for ascending sorting or descending sorting, $left is the left index and $right is the right index. The default sort is ASC. $left and $right are optional. Greets, CK1 http://wwwtech.de

« previous php.notes (#94487) next »