PHP Array Splitten

  • Moin,



    ich melde mich mal zurück und bräuchte ein gedankensprung wie ich diese sache am besten Löse.
    Ich lese etwas aus einer Datenbank aus und erhalte ein Array mit folgenden werten.



    wie kann ich das nun so Splitten, das ich den ersten Wert mit den ersten Int Wert verknüpfe ?


    Habe mir in der Richtung etwas gedacht wie ich das am Ende auslesen mag, wenn es so am sinnvollsten ist.


    PHP
    $VDStatus = array(
    	"I_Heli_Transport_02_F" => array(
    		"HitHull" => array("0" => "NOT DAMAGE", "1" => "DAMAGE"),
    		"HitEngine1" => array("0" => "NOT DAMAGE", "1" => "DAMAGE")
    	),
    	"I_Heli_Transport_01_F" => array(
    		"HitHull" => array("0" => "NOT DAMAGE", "1" => "DAMAGE"),
    		"HitEngine1" => array("0" => "NOT DAMAGE", "1" => "DAMAGE")
    	)
    );
  • Hab das "bis jetzt" unnötig mal weggelassen.
    Die Methode hier setzt vorraus das die Zahlen unten immer dem obrigen Namen entsprechen. Korrigier mich falls ich das falsch verstanden habe:


    Erzeugt dann die folgende Ausgabe, die meiner Meinug nach nun einfach zu handhaben ist:


    seekrass approved
    4x vom Discord geflogen


    shoxinat0r 4
    dennismitzwein 2
    Trooper[Y] 2
    maddin 1
    Unbekannter Discord Kick 2
  • PHP
    $newarray = array();
    foreach((array)$row->damage[0] as $key => $value) {
    	$newarray[$value] = $row->damage[2][$key];
    } 
    var_dump($newarray);
    var_dump($row->damage);

    array(1) { ["["]=> string(1) """}



    string(922) "[["HitHull","HitFuel","HitAvionics","HitEngine1","HitEngine2","HitEngine","HitHRotor","HitVRotor","HitMissiles","HitRGlass","HitLGlass","HitEngine3","HitWinch","HitTransmission","HitGlass1","HitGlass2","HitGlass3","HitGlass4","HitGlass5","HitGlass6","HitLight","HitHydraulics","HitGear","HitHStabilizerL1","HitHStabilizerR1","HitVStabilizer1","HitTail","HitPitotTube","HitStaticPort","HitStarter1","HitStarter2","HitStarter3","","HitTurret","HitGun","HitTurret","HitGun","HitTurret","HitGun"],["hull_hit","fuel_hit","avionics_hit","engine_1_hit","engine_2_hit","engine_hit","main_rotor_hit","tail_rotor_hit","","","","","slingload0","transmission","","","","","","","","","gear","hstabilizerl1","hstabilizerr1","vstabilizer1","tail boom","pitot tube","static port","starter1","starter2","","light_hitpoint","","","","","",""],[1,1,1,1,1,1,1,1,1,1,1,1,1,0.0233079,0,0,0,0,0,0,0,0,0,0,0,0.0377239,0,0,0,0,0,0,0,0,0,0,0,0,0]]"

  • Ist ja auch ein string kein Array.

    PHP
    $array = array($row->damage);
    $newarray = array();
    foreach($array[0] as $key => $value) {
    	$newarray[$value] = $array[2][$key];
    } 
    var_dump($newarray);

    seekrass approved
    4x vom Discord geflogen


    shoxinat0r 4
    dennismitzwein 2
    Trooper[Y] 2
    maddin 1
    Unbekannter Discord Kick 2
  • Mein Fehler. Array konvertiert natürlich nicht^^
    Das:¨

    PHP
    $array = array($row->damage);


    Zu dem ändern:


    PHP
    $array = json_decode($row->damage);

    seekrass approved
    4x vom Discord geflogen


    shoxinat0r 4
    dennismitzwein 2
    Trooper[Y] 2
    maddin 1
    Unbekannter Discord Kick 2