PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Sortierfunktionen für arrays


CThuy
10.07.2004, 22:49:05
Ist nicht super wichtig, Ausgabe nur einfach unschön.

Habe z.B.


$a=array(9,10,11,23,24);
for($i=0;$i< count($a);$i++)
$a[$i]=$a[$i]." a";
$b=array(9,10,11);
for($i=0;$i< count($b);$i++)
$b[$i]=$b[$i]." b";
$c=array(9,10);
for($i=0;$i< count($c);$i++)
$c[$i]=$c[$i]." c";
$d=array(9,10);
for($i=0;$i< count($d);$i++)
$d[$i]=$d[$i]." d";
$e=array(10,11);
for($i=0;$i< count($e);$i++)
$e[$i]=$e[$i]." e";
$f=array(10,11);
for($i=0;$i< count($f);$i++)
$f[$i]=$f[$i]." f";

$kartenwahl=array_merge($a,$b);
$kartenwahl=array_merge($kartenwahl,$c);
$kartenwahl=array_merge($kartenwahl,$d);
$kartenwahl=array_merge($kartenwahl,$e);
$kartenwahl=array_merge($kartenwahl,$f);
sort($kartenwahl);

$anz=count($kartenwahl);

for($i=0;$i< $anz;$i++)
print "Sitz ".$kartenwahl[$i]."<br>";


Bei Ausgabe ergibt sich dann folgende Reihenfolge:
10a, 10b, 10c, 10d, 10e, 10f, 11a, 11b, 11e, 11f, 23a, 24a, 9a,9b, 9c, 9d

Warum? Wieso sind die "9er-Werte" für PHP höher? Sind doch jetzt string-WErte, oder?

Kann man hier noch irgendetwas tun, damit die "9er-WErte" an Anfang stehen?
Ich sehe keine Sortierfunktion für arrays, die mir da weiterhelfen würde.
Wenn dann eine Funktion: welche Bedingung müsste ich dann erfragen?

Ratlos

Claudia

chris17
10.07.2004, 23:39:10
Hallo,

hier hilft Dir usort($kartenwahl, 'strnatcmp'); (http://de.php.net/manual/de/function.usort.php) weiter.

Grüße