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