Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this 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);
?>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP  and MySQL Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to Refresh a Page Periodically Using PHP... >>
<< How to Delete PHP Array Element by Value Not Key...