X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;ds=sidebyside;f=functions%2Farray.php;h=09fc992bbf02a1e94f6681da3cb0f2b27fd09123;hb=a615e36190f51e5c4705e80b77fe29404ea37478;hp=f65b8f86cf857dac0680daecb6548496ef91dbae;hpb=7350889b45590aee831ba1150ee94efb95b03992;p=squirrelmail.git diff --git a/functions/array.php b/functions/array.php index f65b8f86..09fc992b 100644 --- a/functions/array.php +++ b/functions/array.php @@ -1,73 +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 */ + if ($dir > 0) { + $dir = 1; + } + else { + $dir = -1; + } + /* Direction, a positive number for ascending a negative for descending */ + $GLOBALS['dir'] = $dir; - 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; - $GLOBALS['dir'] = $dir; // Direction, a positive number for ascending a negative for descending - - usort($ary,'array_comp2'); - return $ary; - } + 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]]){ - $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 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; - } + } + } + return $newArray; +} - function array_cleave($array1, $column) - { +function array_cleave($array1, $column) +{ $key=0; $array2 = array(); while ($key < count($array1)) { array_push($array2, $array1[$key][$column]); $key++; } - return ($array2); - } +} ?>