[PHP Array] Zusammenführung zweier Arrays

fragger1991

New Member
Hallo,

ich glaube bei mir steht gerade nen ziemlich dicker Panzer auf der Leitung :S

Ich habe 2 Arrays, welche ich quasi Zusammenführen möchte. Einmal habe ich ein Array mit Default Daten, das andere Array sind die Individuellen Einstellungen, nun möchte ich den Wert des Default Arrays gerne mit den Individuellen Einstellungen tauschen.

optionid aus dem Individuellen Array ist gleich id aus dem Default Array.

Default Array:
PHP:
Array
(
    [0] => Array
        (
            [id] => 1
            [game] => cod4
            [name] => Mod
            [option] => +set fs_game
            [value] => mods/modwarfare
            [valuetyp] => string
            [valuetypval] => SimpleXMLElement Object
                (
                )

        )

    [1] => Array
        (
            [id] => 3
            [game] => cod4
            [name] => Pure
            [option] => +set sv_pure
            [value] => 1
            [valuetyp] => select
            [valuetypval] => 0;1
        )

    [2] => Array
        (
            [id] => 4
            [game] => cod4
            [name] => Punkbuster
            [option] => +set sv_punkbuster
            [value] => 1
            [valuetyp] => select
            [valuetypval] => 0;1
        )

    [3] => Array
        (
            [id] => 5
            [game] => cod4
            [name] => Standard Config
            [option] => +exec
            [value] => server.cfg
            [valuetyp] => string
            [valuetypval] => SimpleXMLElement Object
                (
                )

        )

)

Array mit den Individuellen Einstellungen:
PHP:
Array
(
    [0] => Array
        (
            [id] => 1
            [serverid] => 3
            [game] => cod4
            [optionid] => 1
            [value] => mods/promodlive211
        )

    [1] => Array
        (
            [id] => 2
            [serverid] => 3
            [game] => cod4
            [optionid] => 3
            [value] => 1
        )

    [2] => Array
        (
            [id] => 3
            [serverid] => 3
            [game] => cod4
            [optionid] => 4
            [value] => 1
        )

    [3] => Array
        (
            [id] => 4
            [serverid] => 3
            [game] => cod4
            [optionid] => 5
            [value] => server.cfg
        )

)

Das ganze rufe ich mit meiner Class ab:
PHP:
	public function getOptionValues($sID) {

		if($this->checkServerExist($sID) == true) {

			$aPOST["content"]["serverid"] = $sID;
			$result1 = simplexml_load_string(gsapiaufruf('getoptions', $aPOST, $this->getApiKeyByServerId($sID)));
			$result1 = call_user_func_array("changeObjectInArray", array($result1));
			$result2 = simplexml_load_string(gsapiaufruf('getsetoptions', $aPOST, $this->getApiKeyByServerId($sID)));
			$result2 = call_user_func_array("changeObjectInArray", array($result2));

			foreach($result2 AS $key2 => $val2) {

				foreach($result1 AS $key => $val) {

					if($val2[optionid] == $val[id]) {
						$val[value] = $val2[value];
					}

					$arr[] = $val;

				}
			}

			return $arr;

		} else {
			return 0;
		}

	}

Ausgegeben bekomme ich dann:
PHP:
Array
(
    [0] => Array
        (
            [id] => 1
            [game] => cod4
            [name] => Mod
            [option] => +set fs_game
            [value] => mods/promodlive211
            [valuetyp] => string
            [valuetypval] => SimpleXMLElement Object
                (
                )

        )

    [1] => Array
        (
            [id] => 3
            [game] => cod4
            [name] => Pure
            [option] => +set sv_pure
            [value] => 1
            [valuetyp] => select
            [valuetypval] => 0;1
        )

    [2] => Array
        (
            [id] => 4
            [game] => cod4
            [name] => Punkbuster
            [option] => +set sv_punkbuster
            [value] => 1
            [valuetyp] => select
            [valuetypval] => 0;1
        )

    [3] => Array
        (
            [id] => 5
            [game] => cod4
            [name] => Standard Config
            [option] => +exec
            [value] => server.cfg
            [valuetyp] => string
            [valuetypval] => SimpleXMLElement Object
                (
                )

        )

    [4] => Array
        (
            [id] => 1
            [game] => cod4
            [name] => Mod
            [option] => +set fs_game
            [value] => mods/modwarfare
            [valuetyp] => string
            [valuetypval] => SimpleXMLElement Object
                (
                )

        )

    [5] => Array
        (
            [id] => 3
            [game] => cod4
            [name] => Pure
            [option] => +set sv_pure
            [value] => 1
            [valuetyp] => select
            [valuetypval] => 0;1
        )

    [6] => Array
        (
            [id] => 4
            [game] => cod4
            [name] => Punkbuster
            [option] => +set sv_punkbuster
            [value] => 1
            [valuetyp] => select
            [valuetypval] => 0;1
        )

    [7] => Array
        (
            [id] => 5
            [game] => cod4
            [name] => Standard Config
            [option] => +exec
            [value] => server.cfg
            [valuetyp] => string
            [valuetypval] => SimpleXMLElement Object
                (
                )

        )

    [8] => Array
        (
            [id] => 1
            [game] => cod4
            [name] => Mod
            [option] => +set fs_game
            [value] => mods/modwarfare
            [valuetyp] => string
            [valuetypval] => SimpleXMLElement Object
                (
                )

        )

    [9] => Array
        (
            [id] => 3
            [game] => cod4
            [name] => Pure
            [option] => +set sv_pure
            [value] => 1
            [valuetyp] => select
            [valuetypval] => 0;1
        )

    [10] => Array
        (
            [id] => 4
            [game] => cod4
            [name] => Punkbuster
            [option] => +set sv_punkbuster
            [value] => 1
            [valuetyp] => select
            [valuetypval] => 0;1
        )

    [11] => Array
        (
            [id] => 5
            [game] => cod4
            [name] => Standard Config
            [option] => +exec
            [value] => server.cfg
            [valuetyp] => string
            [valuetypval] => SimpleXMLElement Object
                (
                )

        )

    [12] => Array
        (
            [id] => 1
            [game] => cod4
            [name] => Mod
            [option] => +set fs_game
            [value] => mods/modwarfare
            [valuetyp] => string
            [valuetypval] => SimpleXMLElement Object
                (
                )

        )

    [13] => Array
        (
            [id] => 3
            [game] => cod4
            [name] => Pure
            [option] => +set sv_pure
            [value] => 1
            [valuetyp] => select
            [valuetypval] => 0;1
        )

    [14] => Array
        (
            [id] => 4
            [game] => cod4
            [name] => Punkbuster
            [option] => +set sv_punkbuster
            [value] => 1
            [valuetyp] => select
            [valuetypval] => 0;1
        )

    [15] => Array
        (
            [id] => 5
            [game] => cod4
            [name] => Standard Config
            [option] => +exec
            [value] => server.cfg
            [valuetyp] => string
            [valuetypval] => SimpleXMLElement Object
                (
                )

        )

)

Ich hoffe ihr versteht was ich meine und es kann einer den Panzer abschleppen :P

Danke!

//EDIT: Ohhh mein Gott wie peinlich :D

PHP:
foreach($res AS $key => $val) {

	foreach($res1 AS $key1 => $val1) {
		if($val1[optionid] == $val[id]) {
			$val[value] = $val1[value];
		}
	}
		$arr[] = $val;
}

statt:
PHP:
			foreach($result2 AS $key2 => $val2) {

				foreach($result1 AS $key => $val) {

					if($val2[optionid] == $val[id]) {
						$val[value] = $val2[value];
					}

					$arr[] = $val;

				}
			}
 
Last edited by a moderator:
Wie ich sehe hast du die Sache mit call_user_func_array noch immer nicht durch Normalaufrufe der jeweiligen Funktionen ersetzt. *Seufz*

Du koenntest folgendes:
PHP:
$aPOST["content"]["serverid"] = $sID;
$result1 = simplexml_load_string(gsapiaufruf('getoptions', $aPOST, $this->getApiKeyByServerId($sID)));
$result1 = call_user_func_array("changeObjectInArray", array($result1));
$result2 = simplexml_load_string(gsapiaufruf('getsetoptions', $aPOST, $this->getApiKeyByServerId($sID)));
 $result2 = call_user_func_array("changeObjectInArray", array($result2));

durch folgendes ersetzen:
PHP:
$aPOST["content"]["serverid"] = $sID;
$result1 = simplexml_load_string(gsapiaufruf('getoptions', $aPOST, $this->getApiKeyByServerId($sID)));
$result1 = changeObjectInArray($result1);
$result2 = simplexml_load_string(gsapiaufruf('getsetoptions', $aPOST, $this->getApiKeyByServerId($sID)));
 $result2 = changeObjectInArray($result2);

Es wird genau das gleiche rauskommen ;)
 
Back
Top