rollback2
[squirrelmail.git] / functions / array.php
... / ...
CommitLineData
1<?php
2
3/**
4 * array.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
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 */
14
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;
32
33 usort($ary,'array_comp2');
34 return $ary;
35}
36
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}
54
55function removeElement($array, $element)
56{
57 $j = 0;
58 for ($i = 0;$i < count($array);$i++) {
59 if ($i != $element) {
60 $newArray[$j] = $array[$i];
61 $j++;
62 }
63 }
64 return $newArray;
65}
66
67function array_cleave($array1, $column)
68{
69 $key=0;
70 $array2 = array();
71 while ($key < count($array1)) {
72 array_push($array2, $array1[$key][$column]);
73 $key++;
74 }
75 return ($array2);
76}
77
78?>