Code cleanup brigage...
[squirrelmail.git] / functions / array.php
1 <?php
2
3 /**
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 */
14
15 /*****************************************************************/
16 /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
17 /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
18 /*** + Base level indent should begin at left margin, as ***/
19 /*** the first line of the function definition below. ***/
20 /*** + All identation should consist of four space blocks ***/
21 /*** + Tab characters are evil. ***/
22 /*** + all comments should use "slash-star ... star-slash" ***/
23 /*** style -- no pound characters, no slash-slash style ***/
24 /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
25 /*** ALWAYS USE { AND } CHARACTERS!!! ***/
26 /*** + Please use ' instead of ", when possible. Note " ***/
27 /*** should always be used in _( ) function calls. ***/
28 /*** Thank you for your help making the SM code more readable. ***/
29 /*****************************************************************/
30
31 function ary_sort($ary,$col, $dir = 1){
32 // The globals are used because USORT determines what is passed to comp2
33 // These should be $this->col and $this->dir in a class
34 // Would beat using globals
35 if(!is_array($col)){
36 $col = array($col);
37 }
38 $GLOBALS['col'] = $col; // Column or Columns as an array
39 if ($dir > 0)
40 $dir = 1;
41 else
42 $dir = -1;
43 $GLOBALS['dir'] = $dir; // Direction, a positive number for ascending a negative for descending
44
45 usort($ary,'array_comp2');
46 return $ary;
47 }
48
49 function array_comp2($a,$b,$i = 0) {
50 global $col;
51 global $dir;
52 $c = count($col) -1;
53 if ($a[$col[$i]] == $b[$col[$i]]){
54 $r = 0;
55 while($i < $c && $r == 0){
56 $i++;
57 $r = comp2($a,$b,$i);
58 }
59 } elseif($a[$col[$i]] < $b[$col[$i]]){
60 return (- $dir);
61 }
62 return $dir;
63 }
64
65 function removeElement($array, $element) {
66 $j = 0;
67 for ($i = 0;$i < count($array);$i++)
68 if ($i != $element) {
69 $newArray[$j] = $array[$i];
70 $j++;
71 }
72
73 return $newArray;
74 }
75
76 function array_cleave($array1, $column)
77 {
78 $key=0;
79 $array2 = array();
80 while ($key < count($array1)) {
81 array_push($array2, $array1[$key][$column]);
82 $key++;
83 }
84
85 return ($array2);
86 }
87
88 ?>