PHP - Function array_push()


Advertisements


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. The length of array increases by the number of variables pushed.

Parameters

Sr.No Parameter & Description
1

array

Required. Specifies an array.

2

var1

Required. value to be pushed.

3

var2

Optional. value to be pushed.

Return Values

Returns the new number of elements in the array.

Example

Try out following example −

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

This will produce the following result −

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

php_function_reference.htm

Advertisements