** -> *
[squirrelmail.git] / functions / array.php
index 8432ee6d440905fed69a13b4020190ddcf6d226e..f65b8f86cf857dac0680daecb6548496ef91dbae 100644 (file)
@@ -1,44 +1,50 @@
-<?
+<?php
+
    /**
-    **  array.php
-    **
-    **  This contains functions that work with array manipulation.  They
-    **  will help sort, and do other types of things with arrays
-    **
-    **/
+    *  array.php
+    *
+    *   Copyright (c) 1999-2001 The Squirrelmail Development 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 = true;
 
    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");
+         $col = array($col);
       }
-      $GLOBALS["col"] = $col;  // Column or Columns as an array
-      $GLOBALS["dir"] = $dir;  // Direction, a positive number for ascending a negative for descending
+      $GLOBALS['col'] = $col;  // Column or Columns as an array
+      if ($dir > 0)
+          $dir = 1;
+      else
+          $dir = -1;
+      $GLOBALS['dir'] = $dir;  // Direction, a positive number for ascending a negative for descending
 
-      usort($ary,comp2);
+      usort($ary,'array_comp2');
       return $ary;
   }
 
-  function comp2($a,$b,$i = 0) {
+  function array_comp2($a,$b,$i = 0) {
          global $col;
          global $dir;
          $c = count($col) -1;
-         if ($a["$col[$i]"] == $b["$col[$i]"]){
+         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]"]){
-            $r = -1 * $dir; // Im not sure why you must * dir here, but it wont work just before the return...
-         } else {
-            $r = 1 * $dir;
-         }
-         return $r;
+         } elseif($a[$col[$i]] < $b[$col[$i]]){
+            return (- $dir);
+         } 
+        return $dir;
       }
 
    function removeElement($array, $element) {
 
       return $newArray;
    }
+
+  function array_cleave($array1, $column)
+  {
+    $key=0;
+    $array2 = array();
+    while ($key < count($array1)) {
+        array_push($array2, $array1[$key][$column]);
+        $key++;
+    }
+
+    return ($array2);
+  }
+
 ?>