Hallo,
ich möchte einem assoziativen Array ein weiteres "assoziatives Element" anhängen und habe folgendes probiert, was allerdings einen Fehler verursacht:
$hosts = array();
array_push ($hosts, "key"=>"value");
ich zitiere mal kurz aus den Kommentaren des manuals:
http://www.php.net/manual/de/function.array-push.php
-------------------------------------------------------------
array_push() doesn't seem to allow you to push a key=>value pair onto
the array.
i.e.:
$myarray = array ();
:
array_push($myarray,"mykey"=>"myvalue");
produces a parsing error.
-------------------------------------------------------------
Regarding:
Carl wrote that: "array_push() doesn't seem to allow you to push a
key=>value pair onto the array."
The correct syntax for this would be:
$array['newkey']=$newvalue;
You should not need the array_push function, but if so the example should
read:
array_push($myarray,array("mykey"=>"myvalue"));
This will not return a syntax error.
-------------------------------------------------------------
Grüße
Andreas