Adding Values to an Array

Posted on 2011-04-24
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 );

My results are:

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

I'd like my results to be:

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

Any assistance is greatly appreciated.
Question by:deharvy
    LVL 38

    Accepted Solution

    $data[] = $newvalue
    Or $data['newkey']=$newvalue
    If you want to specify the key

    Author Closing Comment

    Works like a charm. Thanks!

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now