0

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.

Kristian Rafteseth
  • 2,002
  • 5
  • 27
  • 46

2 Answers2

4

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

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

$r["NO"]["blabla"] = "hey";
Matthew Blancarte
  • 8,251
  • 2
  • 25
  • 34
1

No, you can't, the key must be unique. You could image the php's associative array as the hash map in other language.

Edit:

For your edited case, you could just do $r["NO"]['blabla'] = 'value';

xdazz
  • 158,678
  • 38
  • 247
  • 274