English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP array_push() function pushes one or more elements to the end of an array (pushes into the stack)
array_push ( $array, $var1 , [,$var2...] );
This function willArrayTreated as a stack, and pass the variable var1, var2 ...push to the end of the array. The length of the array will increase according to the number of variables pushed in.
Serial Number | Parameters and Description |
---|---|
1 | array(Required) It specifies an array. |
2 | var1(Required) The value to be pushed in. |
3 | var2(Optional) The value to be pushed in. |
It returns the new number of elements in the array.
Push an element to the end of an array and increase the length of the array1
<?php $input = array("a"=>"banana","b"=>"apple","c"=>"orange"); print_r(array_push($input, "mango")); print_r("\n"); print_r($input ); ?>Test and see‹/›
Output result:
4 Array ( [a] => banana [b] => apple [c] => orange [0] => mango )