Search code examples
phparraysarray-push

PHP, How to push elements into this array?


Example array:

$r["NO"] = array(
"hello" => "hey",
"hey" => array("oij", "ioj"),
"hola" => "hia"
);

How can I add

"blabla" => "hey"

Now in the bottom of that array?

End result should be:

$r["NO"] = array(
"hello" => "hey",
"hey" => array("oij", "ioj"),
"hola" => "hia",
"blabla" => "hey"
);

i tried various array_push without any luck.


Solution

  • You can't have duplicate keys within an associative array.

    Update:: You can just set the key => value like so:

    $r["NO"]["blabla"] = "hey";