Definition
The array_push() function inserts one or more elements to the end of an array.
Syntax
array_push(array, value1, value2, ...)
Parameters
Parameter | Description |
---|---|
array |
Required. Specifies an array. |
value1 |
Optional. Specifies the value to add. |
value2 |
Optional. Specifies the value to add. |
Example
<?php
// Example 1
$cities = array("New York", "Salt Lake", "Tokyo");
array_push($cities,"Berlin", "London");
print_r($cities);
echo "<br>";
// Example 2
$ages = array("Mark" => 22, "Jeff" => 32, "Mike" => 28);
array_push($ages,"Ron", "Harry");
print_r($ages);
echo "<br>";