Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP array_push() Function

PHP array_push() Function

PHP Array ReferenceComplete PHP Array Reference Manual

Example

Insert "blue" and "yellow" at the end of an array:

Run Example »


Definition and Usage

The array_push() function inserts one or more elements at 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 the example below).


Syntax

array_push(

array,value1,value2...

)

Parameters 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:

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

Run Example »


PHP Array ReferenceComplete PHP Array Reference Manual