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.

2
  • "hey" already maps to array("oij", "ioj"),. Commented Mar 6, 2013 at 1:27
  • I think you could not do this since "hey" will be a duplicated key. B. Commented Mar 6, 2013 at 1:27

2 Answers 2

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";
Sign up to request clarification or add additional context in comments.

2 Comments

that was not intentional, changed it now.
@KristianRafteseth No harm, no foul, no need to feel stupid! Happy to help. :)
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';

1 Comment

it was not intentional so changed it now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.