X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=functions%2Farray.php;h=d17662bbdb22bba67612bf1abbe30a124b49dc8a;hp=049f63ca56b89abe0ba740ab97c85d211a59554c;hb=d5811b5c521b9ffaf9a99a944da7248a60bd26f1;hpb=20db5033a7f36d40c7fe11d561069de9c9a2a970 diff --git a/functions/array.php b/functions/array.php index 049f63ca..d17662bb 100644 --- a/functions/array.php +++ b/functions/array.php @@ -1,41 +1,69 @@ -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 - - function comp2($a,$b,$i = 0) { + $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,'array_comp2'); + return $ary; + } + + 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; } - - usort($ary,comp2); - return $ary; + + 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); + } + ?>