changed <? to <?php in everything
[squirrelmail.git] / functions / array.php
1 <?php
2 /**
3 ** array.php
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 $array_php = true;
11
12 function ary_sort($ary,$col, $dir = 1){
13 // The globals are used because USORT determines what is passed to comp2
14 // These should be $this->col and $this->dir in a class
15 // Would beat using globals
16 if(!is_array($col)){
17 $col = array("$col");
18 }
19 $GLOBALS["col"] = $col; // Column or Columns as an array
20 $GLOBALS["dir"] = $dir; // Direction, a positive number for ascending a negative for descending
21
22 usort($ary,comp2);
23 return $ary;
24 }
25
26 function comp2($a,$b,$i = 0) {
27 global $col;
28 global $dir;
29 $c = count($col) -1;
30 if ($a["$col[$i]"] == $b["$col[$i]"]){
31 $r = 0;
32 while($i < $c && $r == 0){
33 $i++;
34 $r = comp2($a,$b,$i);
35 }
36 } elseif($a["$col[$i]"] < $b["$col[$i]"]){
37 $r = -1 * $dir; // Im not sure why you must * dir here, but it wont work just before the return...
38 } else {
39 $r = 1 * $dir;
40 }
41 return $r;
42 }
43
44 function removeElement($array, $element) {
45 $j = 0;
46 for ($i = 0;$i < count($array);$i++)
47 if ($i != $element) {
48 $newArray[$j] = $array[$i];
49 $j++;
50 }
51
52 return $newArray;
53 }
54 ?>