jankli
jankli

Reputation: 41

using array_push($var); with keys

$dizi = array(
"tr" => "Turkey",
"uk" => "United Kingdom",
"us" => "United States"
);

i want to add "br"=>"brasil" to end of the array.

thanks.

Upvotes: 1

Views: 485

Answers (3)

mario
mario

Reputation: 145492

A syntax construct that's a bit closer to array_push would be:

 $dizi += array("br" => "Brasil");

Note the +=
But for a single addition you should prefer the direct array assignment (as pointed out in the other answers).

Upvotes: 1

Jamie
Jamie

Reputation: 116

you could just do:

$dizi['br'] = "brasil"

Upvotes: 1

Jon
Jon

Reputation: 437584

There's nothing to it:

$dizi['br'] = 'brasil';

Upvotes: 5

Related Questions