We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Adding Values to an Array

deharvy
deharvy asked
on
Medium Priority
275 Views
Last Modified: 2012-08-14
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.
Comment
Watch Question

Director, SD-WAN Solutions
CERTIFIED EXPERT
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
Works like a charm. Thanks!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.