The PHP array_push()
function inserts one or more elements to the end of an array.
The function is written as follows:
array_push(arr, value1, value2, ...)
The following example uses the array_push()
function to add elements to an array:
<?php$arr = array("dog", "snake");array_push($arr, "dove", "panda", "hippo");print_r($arr);?>
According to PHP’s official documentation,
array_push()
is optimal when used for inserting multiple elements into an array at once; however, it is not optimal for single insertions.