array_push (arrName, varName) function in php

array_push() function use an array as a stack, and it pushes the passed variables at the end of the array. The length of the array increases automatically by the number of variables pushed into the array_push function. It accepts two parameters, the first parameter to be an array and the second parameter can be any type of value.

array_push : Point To be remembered:

array_push() function() create a warning if the first argument passed in array_push is not an array.

Example :

<?php

$fruits = array("apple", "grapes");

array_push($fruits, "papaya");

print_r($fruits);

?>

 

Output of array_push() function example
Output of array_push() function example

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top