X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Farray.php;h=bd85eff27932cc3d9d76647124e6d38ee22e80e4;hb=1e18bf95e242d2df4a7f6fd14d2fc06fe4b19553;hp=be81def2b031741f7ff91574eadf02f69e96e2a7;hpb=5917742752bea11a547aeba6e4102dd3655b4800;p=squirrelmail.git diff --git a/functions/array.php b/functions/array.php index be81def2..bd85eff2 100644 --- a/functions/array.php +++ b/functions/array.php @@ -1,54 +1,78 @@ 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 - $GLOBALS["dir"] = $dir; // Direction, a positive number for ascending a negative for descending +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,comp2); - return $ary; - } + usort($ary,'array_comp2'); + return $ary; +} - function 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]"]){ - $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; - } +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) { +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); +} - return $newArray; - } ?>