How to use array push in PHP
In this article, I will explain how the array_push() function can be used in PHP.
array_push() function in PHP
-
The array_push() function is used to inserts one or more elements to the end of an array.
-
The array_push function treats array as a stack.
-
In array_push() function, your added elements will always have numeric keys, if your array has string keys.
Syntax
array_push(array,value1,value2) |
Parameter
-
array array is required parameter. Specifies an array.
-
value1 value is required parameter. value to be pushed in array.
-
value2 value is optional parameter. value to be pushed in array.
Example
The following example show to how the array_push() function can be used in PHP.
<html>
<body>
<h3 style="color: silver;">array_push() function example in PHP</h3>
<?php
$a1=array("Student".'<br/>',"Teacher".'<br/>',"Engg.".'<br/>');
echo("pop value<br/>");
print_r(array_push($a1,"Advocate"));
print_r("<br/>");
print_r($a1);
?>
</body>
</html>
|
Output

You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here