Fixed a bug in displaying email addresses in the message list.
[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
7ce342dc 19
20 usort($ary,comp2);
21 return $ary;
22 }
23
24 function comp2($a,$b,$i = 0) {
3302d0d4 25 global $col;
26 global $dir;
27 $c = count($col) -1;
28 if ($a["$col[$i]"] == $b["$col[$i]"]){
29 $r = 0;
30 while($i < $c && $r == 0){
31 $i++;
32 $r = comp2($a,$b,$i);
33 }
34 } elseif($a["$col[$i]"] < $b["$col[$i]"]){
35 $r = -1 * $dir; // Im not sure why you must * dir here, but it wont work just before the return...
36 } else {
37 $r = 1 * $dir;
38 }
39 return $r;
40 }
3302d0d4 41?>