Tutorials Point


  Learning PHP
  Advanced PHP
  PHP Function Reference
  PHP Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

PHP Function array_push()


previous

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.

Paramters

ParameterDescription
arrayRequired. Specifies an array.
var1Required. value to be pushed.
var2Optional. 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("<br />");
print_r($array );
?> 

This will produce following result:

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

previous Printer Friendly

Advertisements


  

Advertisements