• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • 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 );
print_r($data);

My results are:

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

I'd like my results to be:

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

Any assistance is greatly appreciated.
0
deharvy
Asked:
deharvy
1 Solution
 
Aaron TomoskyTechnology ConsultantCommented:
$data[] = $newvalue
Or $data['newkey']=$newvalue
If you want to specify the key
0
 
deharvyAuthor Commented:
Works like a charm. Thanks!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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