How to Push Both Key and Value Into an Array in PHP
[]
You can simply use the square bracket [] notation to add or push a key and value pair into a PHP associative array. Let's take a look at an example to understand how it basically works:
<?php // Sample array $array = array("a" => "Apple", "b" => "Ball", "c" => "Cat"); // Adding key-value pairs to an array $array["d"] = "Dog"; $array["e"] = "Elephant"; print_r($array); ?>
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Use the Square Bracket
[]SyntaxYou can simply use the square bracket
need an explanation for this answer? contact us directly to get an explanation for this answer[]notation to add or push a key and value pair into a PHP associative array. Let's take a look at an example to understand how it basically works: