File: array.php

package info (click to toggle)
squirrelmail 1%3A1.2.6-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 8,300 kB
  • ctags: 4,949
  • sloc: php: 21,297; perl: 2,538; sh: 350; ansic: 122; makefile: 69
file content (78 lines) | stat: -rw-r--r-- 1,729 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php

/**
 * array.php
 *
 * Copyright (c) 1999-2002 The SquirrelMail Project Team
 * Licensed under the GNU GPL. For full terms see the file COPYING.
 *
 * This contains functions that work with array manipulation.  They
 * will help sort, and do other types of things with arrays
 *
 * $Id: array.php,v 1.21 2001/12/23 07:42:38 thomppj Exp $
 */

function ary_sort($ary,$col, $dir = 1)
{
    /* The globals are used because USORT determines what is passed to comp2 */
    /* These should be $this->col and $this->dir in a class */
    /* Would beat using globals */
    if (!is_array($col)) {
        $col = array($col);
    }
    $GLOBALS['col'] = $col;  /* Column or Columns as an array */
    if ($dir > 0) {
        $dir = 1;
    }
    else {
        $dir = -1;
    }
    /* Direction, a positive number for ascending a negative for descending */
    $GLOBALS['dir'] = $dir;

    usort($ary,'array_comp2');
    return $ary;
}

function array_comp2($a,$b,$i = 0)
{
    global $col;
    global $dir;
    $c = count($col) -1;
    if ($a[$col[$i]] == $b[$col[$i]]) {
        $r = 0;
        while ($i < $c && $r == 0) {
            $i++;
            $r = comp2($a,$b,$i);
        }
    }
    elseif ($a[$col[$i]] < $b[$col[$i]]) {
        return (- $dir);
    } 
    return $dir;
}

function removeElement($array, $element)
{
    $j = 0;
    for ($i = 0;$i < count($array);$i++) {
        if ($i != $element) {
            $newArray[$j] = $array[$i];
            $j++;
        }
    }
    return $newArray;
}

function array_cleave($array1, $column)
{
    $key=0;
    $array2 = array();
    while ($key < count($array1)) {
        array_push($array2, $array1[$key][$column]);
        $key++;
    }
    return ($array2);
}

?>