• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

Adding Values to an Array

How can I add a key/value set to an array?

I tried using array_push, but it doesn't seem to be working. Here is what I tried:

$string = "300=>null";
$data = array( '200'=>null );
array_push($data, $string );

My results are:

Array ( [200] => [201] => '300'=>null )

I'd like my results to be:

Array ( [200] => [300] => )

Any assistance is greatly appreciated.
1 Solution
Aaron TomoskySD-WAN SimplifiedCommented:
$data[] = $newvalue
Or $data['newkey']=$newvalue
If you want to specify the key
deharvyAuthor Commented:
Works like a charm. Thanks!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now