Learning PHP
Advanced PHP
PHP Function Reference
PHP Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM
|
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. The length of array increases by the number of variables pushed.
Paramters
Parameter | Description |
array | Required. Specifies an array. |
var1 | Required. value to be pushed. |
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("<br />");
print_r($array );
?>
|
This will produce following result:
4
Array ( [a] => banana [b] => apple [c] => orange [0] => mango )
|
|
|
|