Einzelnen Beitrag anzeigen
  #1  
Alt 22.01.2008, 20:05:48
Leblondi Leblondi ist offline
Anfänger
 
Registriert seit: Jan 2008
Beiträge: 5
Mehrdimensionales Array sortieren

Hallo,

ich habe ein Problem mit der Sortierung des folgenden Array.


Die Daten kommen aus einer Datenbank und werden mit einer Schleife so in das Array geschrieben:
PHP-Code:
$array_Room[$i][$j][$OutputOrder[$key][0]][$OutputOrder[$key][1]][$key] = $val
über das Array
PHP-Code:
$OutputOrder[$key
wird ein Sortierschlüssel zurückgegeben.

Als Ergebnis bekomme ich bei Auslesen des Array´s folgendes zurück:

0 / 0 / 5 / 1 / RoomID / 1
0 / 0 / 5 / 2 / Description / Doppelzimmer, D / WC, Radio, TV, Telefon, Haarföhn, teilweise mit Balkon
0 / 0 / 10 / 1 / AdultDay_Price / 95.00
0 / 0 / 10 / 2 / AdultSkipass_Price / 140.00
0 / 0 / 20 / 1 / 3Person_Price /
0 / 0 / 20 / 2 / 4Person_Price /
0 / 0 / 30 / 1 / 00ChildDay_Price / 45.00
0 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50
0 / 0 / 40 / 1 / 10ChildDay_Price / 55.00
0 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50
0 / 0 / 1 / 1 / TimeDescription / Sportwochen
0 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00
0 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00
1 / 0 / 5 / 1 / RoomID / 2
1 / 0 / 5 / 2 / Description / Doppelzimmer, Bad / WC, Radio, TV, Telefon, Haarföhn, teilweise mit Balkon
1 / 0 / 10 / 1 / AdultDay_Price / 97.00
1 / 0 / 10 / 2 / AdultSkipass_Price / 140.00
1 / 0 / 20 / 1 / 3Person_Price /
1 / 0 / 20 / 2 / 4Person_Price /
1 / 0 / 30 / 1 / 00ChildDay_Price / 45.00
1 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50
1 / 0 / 40 / 1 / 10ChildDay_Price / 55.00
1 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50
1 / 0 / 1 / 1 / TimeDescription / Sportwochen
1 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00
1 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00
2 / 0 / 5 / 1 / RoomID / 3
2 / 0 / 5 / 2 / Description / Einbettzimmer, D / WC, Radio, TV, Telefon, Haarföhn
2 / 0 / 10 / 1 / AdultDay_Price / 95.00
2 / 0 / 10 / 2 / AdultSkipass_Price / 140.00
2 / 0 / 20 / 1 / 3Person_Price /
2 / 0 / 20 / 2 / 4Person_Price /
2 / 0 / 30 / 1 / 00ChildDay_Price / 45.00
2 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50
2 / 0 / 40 / 1 / 10ChildDay_Price / 55.00
2 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50
2 / 0 / 1 / 1 / TimeDescription / Sportwochen
2 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00
2 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00
3 / 0 / 5 / 1 / RoomID / 4
3 / 0 / 5 / 2 / Description / Studiozimmer, Bad / WC, Radio, TV, Telefon, Sitzecke
3 / 0 / 10 / 1 / AdultDay_Price / 100.00
3 / 0 / 10 / 2 / AdultSkipass_Price / 140.00
3 / 0 / 20 / 1 / 3Person_Price /
3 / 0 / 20 / 2 / 4Person_Price /
3 / 0 / 30 / 1 / 00ChildDay_Price / 45.00
3 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50
3 / 0 / 40 / 1 / 10ChildDay_Price / 55.00
3 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50
3 / 0 / 1 / 1 / TimeDescription / Sportwochen
3 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00
3 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00
4 / 0 / 5 / 1 / RoomID / 5
4 / 0 / 5 / 2 / Description / Appartment A 45 m2, 3 Pers. € 55,- 4 Pers. € 47,- pro Tag mit HP / Kinder
4 / 0 / 10 / 1 / AdultDay_Price / 107.00
4 / 0 / 10 / 2 / AdultSkipass_Price / 140.00
4 / 0 / 20 / 1 / 3Person_Price / 55.00
4 / 0 / 20 / 2 / 4Person_Price / 47.00
4 / 0 / 30 / 1 / 00ChildDay_Price / 45.00
4 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50
4 / 0 / 40 / 1 / 10ChildDay_Price / 55.00
4 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50
4 / 0 / 1 / 1 / TimeDescription / Sportwochen
4 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00
4 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00
5 / 0 / 5 / 1 / RoomID / 6
5 / 0 / 5 / 2 / Description / Appartment B 48 m2, 3 Pers. € 63,- 4 Pers. € 55,- pro Tag mit HP / Kinder
5 / 0 / 10 / 1 / AdultDay_Price / 117.00
5 / 0 / 10 / 2 / AdultSkipass_Price / 140.00
5 / 0 / 20 / 1 / 3Person_Price / 63.00
5 / 0 / 20 / 2 / 4Person_Price / 55.00
5 / 0 / 30 / 1 / 00ChildDay_Price / 45.00
5 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50
5 / 0 / 40 / 1 / 10ChildDay_Price / 55.00
5 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50
5 / 0 / 1 / 1 / TimeDescription / Sportwochen
5 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00
5 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00

Nun möchte ich das ganze nach den Spalten 3 (0 / 0 / 1 / 1 /), 1 (0 / 0 / 1 / 1 /) und 4 (0 / 0 / 1 / 1 /) sortieren, allerdings schaut das Ergebnis dann leider so aus: (hier wurde nur nach Spalte 3 (0 / 0 / 1 / 1 /) sortiert)

4 / 0 / 5 / 1 / RoomID / 5
4 / 0 / 5 / 2 / Description / Appartment A 45 m2, 3 Pers. € 55,- 4 Pers. € 47,- pro Tag mit HP / Kinder
4 / 0 / 10 / 1 / AdultDay_Price / 107.00
4 / 0 / 10 / 2 / AdultSkipass_Price / 140.00
4 / 0 / 20 / 1 / 3Person_Price / 55.00
4 / 0 / 20 / 2 / 4Person_Price / 47.00
4 / 0 / 30 / 1 / 00ChildDay_Price / 45.00
4 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50
4 / 0 / 40 / 1 / 10ChildDay_Price / 55.00
4 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50
4 / 0 / 1 / 1 / TimeDescription / Sportwochen
4 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00
4 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00
5 / 0 / 5 / 1 / RoomID / 6
5 / 0 / 5 / 2 / Description / Appartment B 48 m2, 3 Pers. € 63,- 4 Pers. € 55,- pro Tag mit HP / Kinder
5 / 0 / 10 / 1 / AdultDay_Price / 117.00
5 / 0 / 10 / 2 / AdultSkipass_Price / 140.00
5 / 0 / 20 / 1 / 3Person_Price / 63.00
5 / 0 / 20 / 2 / 4Person_Price / 55.00
5 / 0 / 30 / 1 / 00ChildDay_Price / 45.00
5 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50
5 / 0 / 40 / 1 / 10ChildDay_Price / 55.00
5 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50
5 / 0 / 1 / 1 / TimeDescription / Sportwochen
5 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00
5 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00
3 / 0 / 5 / 1 / RoomID / 4
3 / 0 / 5 / 2 / Description / Studiozimmer, Bad / WC, Radio, TV, Telefon, Sitzecke
3 / 0 / 10 / 1 / AdultDay_Price / 100.00
3 / 0 / 10 / 2 / AdultSkipass_Price / 140.00
3 / 0 / 20 / 1 / 3Person_Price /
3 / 0 / 20 / 2 / 4Person_Price /
3 / 0 / 30 / 1 / 00ChildDay_Price / 45.00
3 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50
3 / 0 / 40 / 1 / 10ChildDay_Price / 55.00
3 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50
3 / 0 / 1 / 1 / TimeDescription / Sportwochen
3 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00
3 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00
2 / 0 / 5 / 1 / RoomID / 3
2 / 0 / 5 / 2 / Description / Einbettzimmer, D / WC, Radio, TV, Telefon, Haarföhn
2 / 0 / 10 / 1 / AdultDay_Price / 95.00
2 / 0 / 10 / 2 / AdultSkipass_Price / 140.00
2 / 0 / 20 / 1 / 3Person_Price /
2 / 0 / 20 / 2 / 4Person_Price /
2 / 0 / 30 / 1 / 00ChildDay_Price / 45.00
2 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50
2 / 0 / 40 / 1 / 10ChildDay_Price / 55.00
2 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50
2 / 0 / 1 / 1 / TimeDescription / Sportwochen
2 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00
2 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00
1 / 0 / 5 / 1 / RoomID / 2
1 / 0 / 5 / 2 / Description / Doppelzimmer, Bad / WC, Radio, TV, Telefon, Haarföhn, teilweise mit Balkon
1 / 0 / 10 / 1 / AdultDay_Price / 97.00
1 / 0 / 10 / 2 / AdultSkipass_Price / 140.00
1 / 0 / 20 / 1 / 3Person_Price /
1 / 0 / 20 / 2 / 4Person_Price /
1 / 0 / 30 / 1 / 00ChildDay_Price / 45.00
1 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50
1 / 0 / 40 / 1 / 10ChildDay_Price / 55.00
1 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50
1 / 0 / 1 / 1 / TimeDescription / Sportwochen
1 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00
1 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00
0 / 0 / 5 / 1 / RoomID / 1
0 / 0 / 5 / 2 / Description / Doppelzimmer, D / WC, Radio, TV, Telefon, Haarföhn, teilweise mit Balkon
0 / 0 / 10 / 1 / AdultDay_Price / 95.00
0 / 0 / 10 / 2 / AdultSkipass_Price / 140.00
0 / 0 / 20 / 1 / 3Person_Price /
0 / 0 / 20 / 2 / 4Person_Price /
0 / 0 / 30 / 1 / 00ChildDay_Price / 45.00
0 / 0 / 30 / 2 / 00ChildSkipass_Price / 86.50
0 / 0 / 40 / 1 / 10ChildDay_Price / 55.00
0 / 0 / 40 / 2 / 10ChildSkipass_Price / 86.50
0 / 0 / 1 / 1 / TimeDescription / Sportwochen
0 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00
0 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00

Richtig wäre es aber so:
0 / 0 / 1 / 1 / TimeDescription / Sportwochen
0 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00
0 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00
1 / 0 / 1 / 1 / TimeDescription / Sportwochen
1 / 0 / 1 / 2 / Startdate / 2008-01-12 00:00:00
1 / 0 / 1 / 3 / Enddate / 2008-02-02 00:00:00

...........
0 / 0 / 5 / 1 / RoomID / 1
0 / 0 / 5 / 2 / Description / Doppelzimmer, D / WC, .....
1 / 0 / 5 / 1 / RoomID / 2
1 / 0 / 5 / 2 / Description / Doppelzimmer, Bad / WC, ....
........
0 / 0 / 10 / 1 / AdultDay_Price / 95.00
0 / 0 / 10 / 2 / AdultSkipass_Price / 140.00
1 / 0 / 10 / 1 / AdultDay_Price / 97.00
1 / 0 / 10 / 2 / AdultSkipass_Price / 140.00
......... u.s.w.


Was mache ich hier falsch ? :-(

Zum sortieren verwende ich
PHP-Code:
uksort($array,vergleich); 
Hier noch die Function:
PHP-Code:
$sortcol=  2;  // Spalte nach der sortiert werden soll
$sortord= -1;  // -1 absteigend / +1 aufsteigend

function vergleich($a,$b)
    {
    global 
$sortcol,$sortord  ;
      if(
$a[$sortcol] == $b[$sortcol]) return 0;
      return (
$a[$sortcol] > $b[$sortcol]) ? $sortord : -$sortord ;
    } 

Besten Dank im Voraus für Eure Hilfe

Leblondi

Geändert von Leblondi (22.01.2008 um 20:09:30 Uhr) Grund: falsche Syntax eingefügt
Mit Zitat antworten