X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Farray.php;h=f65b8f86cf857dac0680daecb6548496ef91dbae;hb=cb48c2455cde2cf6ba67944c45decc4eca7df306;hp=b59f21c960e76612ae1fa8cb32c3881319c32bb2;hpb=245a6892bf5c780904ef9677f24d624ea17e0749;p=squirrelmail.git diff --git a/functions/array.php b/functions/array.php index b59f21c9..f65b8f86 100644 --- a/functions/array.php +++ b/functions/array.php @@ -1,45 +1,50 @@ 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) { @@ -58,7 +63,7 @@ $key=0; $array2 = array(); while ($key < count($array1)) { - array_push($array2, $array1[$key]["$column"]); + array_push($array2, $array1[$key][$column]); $key++; }