PHP array_push()Functions
Complete PHP Array Reference Manual
Examples
Insert "blue" and "yellow" at the end of the array:
<?php
$a=array("red","green");
array_push($a,"blue","yellow");
print_r($a);
?>
$a=array("red","green");
array_push($a,"blue","yellow");
print_r($a);
?>
Run example »
Definition and Usage
The array_push() function inserts one or more elements to the end of an array.
Tip:You can add one or more values.
Note:Even if your array has string keys, the elements you add will have numeric keys (see example below).
Syntax
array_push(array,value1,value2...)
| Parameter | Description |
|---|---|
| array | Required. Specifies an array. |
| value1 | Required. Specifies the value to add. |
| value2 | Optional. Specifies the value to add. |
Technical Details
| Return value: | Returns the number of elements in the new array. |
|---|---|
| PHP Version: | 4+ |
More Examples
Example 1
An array with string keys:
<?php
$a=array("a"=>"red","b"=>"green");
array_push($a,"blue","yellow");
print_r($a);
?>
$a=array("a"=>"red","b"=>"green");
array_push($a,"blue","yellow");
print_r($a);
?>
Run example »
Complete PHP Array Reference Manual Other Extensions