How to Add an Element to an Array in PHP
In this lesson, we will see how to add an element to an array in PHP, PHP has a built-in function that does that called array_push.
Add element to the array
The example below shows how you can add an element to an array using the array_push built-in function.
$names = array("jack", "john", "sam");
array_push($names, 'bob');
echo $names[3];
//bob