added color customization
[squirrelmail.git] / functions / array.php
CommitLineData
3302d0d4 1<?
2 /**
a09387f4 3 ** array.php
3302d0d4 4 **
5 ** This contains functions that work with array manipulation. They
6 ** will help sort, and do other types of things with arrays
7 **
8 **/
9
10 function ary_sort($ary,$col, $dir = 1){
11 // The globals are used because USORT determines what is passed to comp2
12 // These should be $this->col and $this->dir in a class
13 // Would beat using globals
14 if(!is_array($col)){
15 $col = array("$col");
16 }
17 $GLOBALS["col"] = $col; // Column or Columns as an array
18 $GLOBALS["dir"] = $dir; // Direction, a positive number for ascending a negative for descending
19
20 function comp2($a,$b,$i = 0) {
21 global $col;
22 global $dir;
23 $c = count($col) -1;
24 if ($a["$col[$i]"] == $b["$col[$i]"]){
25 $r = 0;
26 while($i < $c && $r == 0){
27 $i++;
28 $r = comp2($a,$b,$i);
29 }
30 } elseif($a["$col[$i]"] < $b["$col[$i]"]){
31 $r = -1 * $dir; // Im not sure why you must * dir here, but it wont work just before the return...
32 } else {
33 $r = 1 * $dir;
34 }
35 return $r;
36 }
37
38 usort($ary,comp2);
39 return $ary;
40 }
41?>