Current Location: Home> Function Categories> array_push

array_push

Push one or more cells into the end of the array (to stack)
Name:array_push
Category:Array
Programming Language:php
One-line Description:Insert one or more elements at the end of the array (to stack).

Definition and usage

array_push() function adds one or more elements (stack) to the end of the array of the first parameter, and then returns the length of the new array.

This function is equal to multiple calls $array[] = $value .

Example

Example 1

Insert "blue" and "yellow" into the tail of the array:

 <?php
$a = array ( "red" , "green" ) ;
array_push ( $a , "blue" , ​​"yellow" ) ;
print_r ( $a ) ;
?>

Try it yourself

Example 2

Array with string key names:

 <?php
$a = array ( "a" => "red" , "b" => "green" ) ;
array_push ( $a , "blue" , ​​"yellow" ) ;
print_r ( $a ) ;
?>

Try it yourself

grammar

 array_push ( array , value1 , value2 ... )
parameter describe
array Required. Specify array.
value1 Required. Specifies the value to be added.
value2 Optional. Specifies the value to be added.
Similar Functions
Popular Articles