gondor: Array Sortieren

Hallo,

ich möchte gerne ein Array sortieren, weiß nur nicht genau wie ich das anfassen soll (evtl. callback?).

Mein Array halt folgenden Aufbau:

Array

(

[0] => Array

(

[id] => 3

[Gruppe] => ADM

)

[1] => Array

(

[id] => 5

[Gruppe] => TEST

)

[2] => Array

(

[id] => 2

[Gruppe] => BUB

)

[3] => Array

(

[id] => 1

[Gruppe] => MedWiss

)

usw...

Jetzt möchte ich nach Gruppe alphabetisch sortieren.

Jemand eine Idee?

Danke,
gondor(..)

  1. Hi,

    Jetzt möchte ich nach Gruppe alphabetisch sortieren.

    Jemand eine Idee?

    usort()

    MfG ChrisB

    --
    „This is the author's opinion, not necessarily that of Starbucks.“
    1. Also doch mit callback ;-)

      function cmp($a, $b) {
        return strcmp($a["Gruppe"], $b["Gruppe"]);
      }

      usort($groups, "cmp");

      Danke für den Hinweis,
      gondor(..)

      Hi,

      Jetzt möchte ich nach Gruppe alphabetisch sortieren.

      Jemand eine Idee?

      usort()

      MfG ChrisB

  2. echo $begrüßung;

    ich möchte gerne ein Array sortieren, weiß nur nicht genau wie ich das anfassen soll (evtl. callback?).
    Jetzt möchte ich nach Gruppe alphabetisch sortieren.

    array_multisort(). Dazu benötigst du aber zuerst deine Sortierspalte in einem eigenen Array.

    $data = array(...); // dein Array  
      
    $sortcolumn = array();  
    foreach ($data as $record)  
      $sortcolumn[] = $record['Gruppe'];  
      
    array_multisort($sortcolumn, $data);
    

    $data liegt nun aufsteigend nach Gruppe sortiert vor. Absteigend wäre auch kein Problem, dazu bekommt array_multisort() als zweiten Paramerer SORT_DESC und $data wandert einen weiter nach hinten.

    echo "$verabschiedung $name";