The PHP add to array function: array_push()

There are two ways to add an element to the end of an array in PHP.

// Create an array
$a = new array("apple", "orange");
 
// Add an element to the end of the array using the array_push() function
array_push($a, "banana")
 
// Alternative way of adding an element to the end of an array
$a[] = "pineapple";
 
// Adding an element with a key
$a['fruit'] = "watermelon";

And that is how you add to array in PHP!