GANZES Array Sortieren

  • PHP

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • GANZES Array Sortieren

    Hallo

    Ich mache momentan ein Projekt wo es um die Sortierung einer Tabelle geht. Die Daten werden in Arrays geladen und der entsprechende Array sortiert. Das Problem; Nur weil die Punkte korrekt sortiert werden, heist das noch lange nicht, das der entsprechende Name auch zugeordnet wird!

    Code-Ausschnitt:

    PHP-Quellcode

    1. $lines = file("content/.htfile",FILE_SKIP_EMPTY_LINES);
    2. $count = count($lines);
    3. $count = $count-1;
    4. $i = 0;
    5. while($i <= $count)
    6. {
    7. $data = explode("<|>",$lines[$i]);
    8. $points[] = intval($data[0]);
    9. $name[] = $data[1];
    10. $pic[] = $data[2];
    11. $counter[] = $data[3];
    12. $i++;
    13. }
    14. $X = 0;
    15. rsort($points);
    16. echo '<table border="0" width="100%">
    17. <tr>
    18. <td><h3><font color="#FF8000">PUNKTE</font></h3></td><td><h3><font color="#FF8000">FOTO</font></h3></td><td><h3><font color="#FF8000">NAME</font></h3></td><td><h3><font color="#FF8000">TOTAL BEWERTUNGEN</font></h3></td>
    19. </tr>';
    20. while($X <= $count)
    21. {
    22. echo "<tr>";
    23. echo '<td><b>'.strval($points[$X]).'</b></td><td><b><img src="'.$pic[$X].'" border="0" height="'.$height.'" width="'.$width.'"></b></td><td><b>'.$name[$X].'</b></td><td><b>'.$counter[$X].'</b></td>';
    24. echo "</tr>";
    25. $X++;
    26. }
    Alles anzeigen


    Ich wollte es mit mehrdimensionalen Arrays lösen, doch da kenne ich mich nicht gut aus.
    :thumbsup:
  • jlsnews schrieb:

    Hallo
    [...]
    Ich wollte es mit mehrdimensionalen Arrays lösen, doch da kenne ich mich nicht gut aus.


    Hallo, also ich habe da einen Ansatz:

    PHP-Quellcode

    1. $lines = file("content/.htteachers",FILE_SKIP_EMPTY_LINES);
    2. $count = count($lines);
    3. $count = $count-1;
    4. $i = 0;
    5. while($i <= $count)
    6. {
    7. $data = explode("<|>",$lines[$i]);
    8. $infos["points"][$i] = intval($data[0]);
    9. $infos["name"][$i] = $data[1];
    10. $infos["pic"][$i] = $data[2];
    11. $infos["counter"][$i] = $data[3];
    12. $i++;
    13. }
    14. $X = 0;
    15. // SORTIERUNG
    16. // ENDE
    17. echo '<table border="0" width="100%">
    18. <tr>
    19. <td><h3><font color="#FF8000">PUNKTE</font></h3></td><td><h3><font color="#FF8000">FOTO</font></h3></td><td><h3><font color="#FF8000">NAME</font></h3></td><td><h3><font color="#FF8000">TOTAL BEWERTUNGEN</font></h3></td>
    20. </tr>';
    21. $width = "100";
    22. $height = "150";
    23. while($X <= $count)
    24. {
    25. echo "<tr>";
    26. echo '<td><b>'.strval($infos["points"][$X]).'</b></td><td><b><img src="'.$infos["pic"][$X].'" border="0" height="'.$height.'" width="'.$width.'"></b></td><td><b>'.$infos["name"][$X].'</b></td><td><b>'.$infos["counter"][$X].'</b></td>';
    27. echo "</tr>";
    28. $X++;
    29. }
    Alles anzeigen


    Jedenfalls bei auskommentierten Teil mit "Sortierung", und dem Befehl array_multisort(), komme ich nicht weiter.
    :thumbsup: