05. april 2004 - 14:47
Der er
4 kommentarer og
1 løsning
Hvordan kan man alfabitisere i php ?
jeg vil gerne vide hvordan man kan alfabitisere i php , da jeg skal bruge det efter bruger ønske ...
05. april 2004 - 15:03
#5
Så kan det her vel bruges ?
function qsort_multiarray($array,$num = 0,$order = "ASC",$left = 0,$right = -1)
{
if($right == -1)
{ $right = count($array) - 1; }
$links = $left;
$rechts = $right;
$mitte = $array[($left + $right) / 2][$num];
if($rechts > $links)
{
do
{
if($order == "ASC")
{
while($array[$links][$num]<$mitte) $links++;
while($array[$rechts][$num]>$mitte) $rechts--;
}
else
{
while($array[$links][$num]>$mitte) $links++;
while($array[$rechts][$num]<$mitte) $rechts--;
}
if($links <= $rechts)
{
$tmp = $array[$links];
$array[$links++] = $array[$rechts];
$array[$rechts--] = $tmp;
}
} while($links <= $rechts);
$array = qsort_multiarray($array,$num,$order,$left, $rechts);
$array = qsort_multiarray($array,$num,$order,$links,$right);
}
return $array;
}
Call the function like this:
$array = qsort_multiarray(array $array,int $n,string $order,int $left,int $right);
$array is the array which should be sorted, int $n is the index of the sort criterium, $order is "ASC" or "DESC" for ascending sorting or descending sorting, $left is the left index and $right is the right index.
The default sort is ASC. $left and $right are optional.