• PHP Video Tutorials

PHP - Function array_push()



Syntax

array_push ( $array, $var1 [, $var2...] );

Definition and Usage

This function treats array as a stack, and pushes the passed variables var1, var2... onto the end of array.

Parameters

Sr.No Parameter & Description
1

array(Required)

It specifies an array.

2

var1(Required)

The value to be pushed.

3

var2(Optional)

The value to be pushed.

Return Values

It returns the new number of elements in the array.

Example

Try out following example −

<?php
   $input = array("a"=>"banana","b"=>"apple","c"=>"orange");
   
   print_r(array_push($input, "mango"));
   print_r("\n");
   print_r($input );
?> 

This will produce the following result −

4 Array ( [a] => banana [b] => apple [c] => orange [0] => mango )
php_function_reference.htm
Advertisements