Updating
[squirrelmail.git] / functions / array.php3
1 <?
2 function ary_sort($ary,$col, $dir = 1){
3 // The globals are used because USORT determines what is passed to comp2
4 // These should be $this->col and $this->dir in a class
5 // Would beat using globals
6 if(!is_array($col)){
7 $col = array("$col");
8 }
9 $GLOBALS["col"] = $col; // Column or Columns as an array
10 $GLOBALS["dir"] = $dir; // Direction, a positive number for ascending a negative for descending
11
12 function comp2($a,$b,$i = 0) {
13 global $col;
14 global $dir;
15 $c = count($col) -1;
16 if ($a["$col[$i]"] == $b["$col[$i]"]){
17 $r = 0;
18 while($i < $c && $r == 0){
19 $i++;
20 $r = comp2($a,$b,$i);
21 }
22 } elseif($a["$col[$i]"] < $b["$col[$i]"]){
23 $r = -1 * $dir; // Im not sure why you must * dir here, but it wont work just before the return...
24 } else {
25 $r = 1 * $dir;
26 }
27 return $r;
28 }
29
30 usort($ary,comp2);
31 return $ary;
32 }
33 ?>