Ergebnis 1 bis 2 von 2
  1. #1
    Avatar von bosko
    bosko ist offline Foren As
    registriert
    04-12-2011
    Beiträge
    97

    PHP Array neu Anordnen

    Hallo,

    mal wieder meine geliebten array's, meine array ausgabe sieht so aus:

    Code:
    Array
    (
        [0] => Array
            (
                [1] => Array
                    (
                        [3] => 17
                    )
    
                [26] => Array
                    (
                        [3] => 1
                    )
    
                [2] => Array
                    (
                        [3] => 5
                    )
    
                [3] => Array
                    (
                        [3] => 4
                    )
    
                [4] => Array
                    (
                        [3] => 2
                    )
    
                [5] => Array
                    (
                        [3] => 2
                    )
    
                [22] => Array
                    (
                        [3] => 2
                    )
    
                [6] => Array
                    (
                        [3] => 12
                    )
    
                [7] => Array
                    (
                        [3] => 2
                    )
    
                [23] => Array
                    (
                        [3] => 2
                    )
    
                [8] => Array
                    (
                        [3] => 2
                    )
    
                [9] => Array
                    (
                        [3] => 9
                    )
    
                [10] => Array
                    (
                        [3] => 1
                    )
    
                [11] => Array
                    (
                        [3] => 43
                    )
    
                [12] => Array
                    (
                        [3] => 46
                    )
    
                [24] => Array
                    (
                        [3] => 2
                    )
    
                [13] => Array
                    (
                        [3] => 3
                    )
    
                [14] => Array
                    (
                        [3] => 7
                    )
    
                [15] => Array
                    (
                        [3] => 4
                    )
    
                [16] => Array
                    (
                        [3] => 3
                    )
    
                [17] => Array
                    (
                        [3] => 4
                    )
    
                [18] => Array
                    (
                        [3] => 1
                    )
    
                [19] => Array
                    (
                        [3] => 11
                    )
    
                [20] => Array
                    (
                        [3] => 16
                    )
    
                [25] => Array
                    (
                        [3] => 1
                    )
    
                [21] => Array
                    (
                        [3] => 9
                    )
    
            )
    
        [1] => Array
            (
                [1] => Array
                    (
                        [4] => 0
                    )
    
                [26] => Array
                    (
                        [4] => 0
                    )
    
                [2] => Array
                    (
                        [4] => 0
                    )
    
                [3] => Array
                    (
                        [4] => 0
                    )
    
                [4] => Array
                    (
                        [4] => 2
                    )
    
                [5] => Array
                    (
                        [4] => 1
                    )
    
                [22] => Array
                    (
                        [4] => 0
                    )
    
                [6] => Array
                    (
                        [4] => 0
                    )
    
                [7] => Array
                    (
                        [4] => 0
                    )
    
                [23] => Array
                    (
                        [4] => 0
                    )
    
                [8] => Array
                    (
                        [4] => 0
                    )
    
                [9] => Array
                    (
                        [4] => 0
                    )
    
                [10] => Array
                    (
                        [4] => 0
                    )
    
                [11] => Array
                    (
                        [4] => 1
                    )
    
                [12] => Array
                    (
                        [4] => 0
                    )
    
                [24] => Array
                    (
                        [4] => 0
                    )
    
                [13] => Array
                    (
                        [4] => 0
                    )
    
                [14] => Array
                    (
                        [4] => 0
                    )
    
                [15] => Array
                    (
                        [4] => 0
                    )
    
                [16] => Array
                    (
                        [4] => 0
                    )
    
                [17] => Array
                    (
                        [4] => 0
                    )
    
                [18] => Array
                    (
                        [4] => 0
                    )
    
                [19] => Array
                    (
                        [4] => 0
                    )
    
                [20] => Array
                    (
                        [4] => 1
                    )
    
                [25] => Array
                    (
                        [4] => 0
                    )
    
                [21] => Array
                    (
                        [4] => 0
                    )
    
            )
    
    )
    nachdem ich diese per PHP versucht habe neu anzuordnen mit:
    PHP-Code:
    foreach ($a as $b => $c) {
          foreach (
    $c as $d => $e) {
              
    $arr[$d][$b] = $e;
          }
      } 
    schaut das ganze so aus:
    Code:
    Array
    (
        [1] => Array
            (
                [0] => Array
                    (
                        [3] => 17
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [26] => Array
            (
                [0] => Array
                    (
                        [3] => 1
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [2] => Array
            (
                [0] => Array
                    (
                        [3] => 5
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [3] => Array
            (
                [0] => Array
                    (
                        [3] => 4
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [4] => Array
            (
                [0] => Array
                    (
                        [3] => 2
                    )
    
                [1] => Array
                    (
                        [4] => 2
                    )
    
            )
    
        [5] => Array
            (
                [0] => Array
                    (
                        [3] => 2
                    )
    
                [1] => Array
                    (
                        [4] => 1
                    )
    
            )
    
        [22] => Array
            (
                [0] => Array
                    (
                        [3] => 2
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [6] => Array
            (
                [0] => Array
                    (
                        [3] => 12
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [7] => Array
            (
                [0] => Array
                    (
                        [3] => 2
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [23] => Array
            (
                [0] => Array
                    (
                        [3] => 2
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [8] => Array
            (
                [0] => Array
                    (
                        [3] => 2
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [9] => Array
            (
                [0] => Array
                    (
                        [3] => 9
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [10] => Array
            (
                [0] => Array
                    (
                        [3] => 1
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [11] => Array
            (
                [0] => Array
                    (
                        [3] => 43
                    )
    
                [1] => Array
                    (
                        [4] => 1
                    )
    
            )
    
        [12] => Array
            (
                [0] => Array
                    (
                        [3] => 46
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [24] => Array
            (
                [0] => Array
                    (
                        [3] => 2
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [13] => Array
            (
                [0] => Array
                    (
                        [3] => 3
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [14] => Array
            (
                [0] => Array
                    (
                        [3] => 7
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [15] => Array
            (
                [0] => Array
                    (
                        [3] => 4
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [16] => Array
            (
                [0] => Array
                    (
                        [3] => 3
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [17] => Array
            (
                [0] => Array
                    (
                        [3] => 4
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [18] => Array
            (
                [0] => Array
                    (
                        [3] => 1
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [19] => Array
            (
                [0] => Array
                    (
                        [3] => 11
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [20] => Array
            (
                [0] => Array
                    (
                        [3] => 16
                    )
    
                [1] => Array
                    (
                        [4] => 1
                    )
    
            )
    
        [25] => Array
            (
                [0] => Array
                    (
                        [3] => 1
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
        [21] => Array
            (
                [0] => Array
                    (
                        [3] => 9
                    )
    
                [1] => Array
                    (
                        [4] => 0
                    )
    
            )
    
    )
    möchte aber das es so aussieht:
    Code:
    Array
    (
        [1] => Array
            (
                [3] => 17,
                [4] => 0
            )
    
        [26] => Array
            (
               [3] => 1,
               [4] => 0
            )
    
        [2] => Array
            (
                [3] => 5,
                [4] => 0
    
            )
    
        [3] => Array
            (
                [3] => 4,
                [4] => 0
    
            )
    wie stelle ich das am besten an? Das die erste zahl (1, 26, 2, 3 ....) so durcheinander ist, ist von mir so gewünscht...

    gruß

  2. #2
    Avatar von kkapsner
    kkapsner ist offline Super Moderator
    registriert
    28-03-2008
    Beiträge
    17.745

    AW: PHP Array neu Anordnen

    Was machst du denn da komisches die letzte Zeit? Irgendwie sieht mir das danach aus, dass du deine Datenstrukturen mal sauber aufbauen solltest.

    Wenn du den Index $b nicht haben will, darfst du ihn natürlich auch nicht verwenden. Wenn du aber dann auf der letzten Ebene einen Index doppelt hast, verlierst du einen Wert.

    Code:
    foreach ($a as $b => $c) {
          foreach ($c as $d => $e) {
              if (array_key_exists($d, $arr)){
                $arr[$d] += $e;
              }
              else {
                $arr[$d] = $e;
              }
          }
      }
    - ungetestet.

Ähnliche Themen

  1. [GELÖST] DIV dynamisch anordnen
    Von sascha83 im Forum JavaScript
    Antworten: 7
    Letzter Beitrag: 15-05-2015, 11:08
  2. elemente anordnen
    Von Noisebreath im Forum CSS und (X)HTML
    Antworten: 9
    Letzter Beitrag: 30-03-2010, 18:41
  3. Anordnen von x-Radiobuttons
    Von jack-x im Forum JavaScript
    Antworten: 3
    Letzter Beitrag: 12-10-2009, 17:16
  4. Formularfelder anordnen
    Von XaTrIxX im Forum JavaScript
    Antworten: 1
    Letzter Beitrag: 07-10-2005, 23:33
  5. alphabetisch anordnen
    Von Bigman007 im Forum Serverseitige Programmierung
    Antworten: 3
    Letzter Beitrag: 07-12-2004, 08:28

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •