59177427 |
1 | <?php |
3302d0d4 |
2 | /** |
2ba13803 |
3 | ** array.php |
4 | ** |
5 | ** Copyright (c) 1999-2001 The Squirrelmail Development Team |
6 | ** Licensed under the GNU GPL. For full terms see the file COPYING. |
7 | ** |
8 | ** This contains functions that work with array manipulation. They |
9 | ** will help sort, and do other types of things with arrays |
10 | ** |
11 | ** $Id$ |
12 | **/ |
f435778e |
13 | |
d068c0ec |
14 | |
3302d0d4 |
15 | function ary_sort($ary,$col, $dir = 1){ |
16 | // The globals are used because USORT determines what is passed to comp2 |
17 | // These should be $this->col and $this->dir in a class |
18 | // Would beat using globals |
19 | if(!is_array($col)){ |
b9bfd165 |
20 | $col = array($col); |
3302d0d4 |
21 | } |
b9bfd165 |
22 | $GLOBALS['col'] = $col; // Column or Columns as an array |
485599c7 |
23 | if ($dir > 0) |
24 | $dir = 1; |
25 | else |
26 | $dir = -1; |
b9bfd165 |
27 | $GLOBALS['dir'] = $dir; // Direction, a positive number for ascending a negative for descending |
7ce342dc |
28 | |
485599c7 |
29 | usort($ary,'array_comp2'); |
7ce342dc |
30 | return $ary; |
31 | } |
32 | |
485599c7 |
33 | function array_comp2($a,$b,$i = 0) { |
3302d0d4 |
34 | global $col; |
35 | global $dir; |
36 | $c = count($col) -1; |
b9bfd165 |
37 | if ($a[$col[$i]] == $b[$col[$i]]){ |
3302d0d4 |
38 | $r = 0; |
39 | while($i < $c && $r == 0){ |
40 | $i++; |
41 | $r = comp2($a,$b,$i); |
42 | } |
b9bfd165 |
43 | } elseif($a[$col[$i]] < $b[$col[$i]]){ |
485599c7 |
44 | return (- $dir); |
45 | } |
46 | return $dir; |
3302d0d4 |
47 | } |
7cad6205 |
48 | |
49 | function removeElement($array, $element) { |
50 | $j = 0; |
51 | for ($i = 0;$i < count($array);$i++) |
52 | if ($i != $element) { |
53 | $newArray[$j] = $array[$i]; |
54 | $j++; |
55 | } |
56 | |
57 | return $newArray; |
58 | } |
5b6ae78a |
59 | |
60 | function array_cleave($array1, $column) |
61 | { |
62 | $key=0; |
63 | $array2 = array(); |
64 | while ($key < count($array1)) { |
b9bfd165 |
65 | array_push($array2, $array1[$key][$column]); |
5b6ae78a |
66 | $key++; |
67 | } |
68 | |
69 | return ($array2); |
70 | } |
71 | |
3302d0d4 |
72 | ?> |