WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES
Advertisements

How to Push Both Key and Value Into an Array in PHP

Topic: PHP / MySQLPrev|Next

Answer: Use the Square Bracket [] Syntax

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);
?>

Related FAQ

Here are some more FAQ related to this topic:

Advertisements
Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties