tags:

views:

511

answers:

2

Hi, I have an existing array and I want to add a value to the array.

Normally I would use array_push() to accomplish this but somehow it's not working. Here is my code:

$data = array(
    "dog" => "cat"
);

array_push($data['pussy'], 'wagon');

I don't simply want to add wagon to the array but also the key pussy so I can retrieve the value like so:

echo $data['pussy']; // this will output wagon

Thanks for your help guys, Max

+6  A: 

so what about having:

$data['pussy']='wagon';

dusoft
Thanks, just saved me a headache :)
Phill Pafford
+5  A: 
$data['pussy'] = 'wagon';

That's all you need to add the key and value to the array.

rogeriopvl
later than me and answer accepted. well, i shouldn't probably answer noobs questions.
dusoft
awww poor you...:D i suggest you take life less seriously!
mistero