** -> *
[squirrelmail.git] / functions / array.php
CommitLineData
59177427 1<?php
7350889b 2
3302d0d4 3 /**
7350889b 4 * array.php
5 *
6 * Copyright (c) 1999-2001 The Squirrelmail Development 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 */
f435778e 14
d068c0ec 15
3302d0d4 16 function ary_sort($ary,$col, $dir = 1){
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)){
b9bfd165 21 $col = array($col);
3302d0d4 22 }
b9bfd165 23 $GLOBALS['col'] = $col; // Column or Columns as an array
485599c7 24 if ($dir > 0)
25 $dir = 1;
26 else
27 $dir = -1;
b9bfd165 28 $GLOBALS['dir'] = $dir; // Direction, a positive number for ascending a negative for descending
7ce342dc 29
485599c7 30 usort($ary,'array_comp2');
7ce342dc 31 return $ary;
32 }
33
485599c7 34 function array_comp2($a,$b,$i = 0) {
3302d0d4 35 global $col;
36 global $dir;
37 $c = count($col) -1;
b9bfd165 38 if ($a[$col[$i]] == $b[$col[$i]]){
3302d0d4 39 $r = 0;
40 while($i < $c && $r == 0){
41 $i++;
42 $r = comp2($a,$b,$i);
43 }
b9bfd165 44 } elseif($a[$col[$i]] < $b[$col[$i]]){
485599c7 45 return (- $dir);
46 }
47 return $dir;
3302d0d4 48 }
7cad6205 49
50 function removeElement($array, $element) {
51 $j = 0;
52 for ($i = 0;$i < count($array);$i++)
53 if ($i != $element) {
54 $newArray[$j] = $array[$i];
55 $j++;
56 }
57
58 return $newArray;
59 }
5b6ae78a 60
61 function array_cleave($array1, $column)
62 {
63 $key=0;
64 $array2 = array();
65 while ($key < count($array1)) {
b9bfd165 66 array_push($array2, $array1[$key][$column]);
5b6ae78a 67 $key++;
68 }
69
70 return ($array2);
71 }
72
3302d0d4 73?>