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