Easy Tutorial
❮ Func Mysqli Next Result Func Array Pad ❯

PHP array_unshift() Function

Complete PHP Array Reference Manual

Example

Insert the element "blue" into the array:


Definition and Usage

The array_unshift() function is used to insert new elements into the array. The new array values will be inserted at the beginning of the array.

Tip: You can insert one or multiple values.

Note: Numeric key names will start from 0 and increment by 1. String key names will remain unchanged.


Syntax

Parameter Description
array Required. Specifies the array.
value1 Required. Specifies the value to insert.
value2 Optional. Specifies the value to insert.
value3 Optional. Specifies the value to insert.

Technical Details

Return Value: Returns the number of elements in the new array.
PHP Version: 4+
--- ---

More Examples

Example 1

Show the return value:

Example 2

Using numeric keys:


❮ Func Mysqli Next Result Func Array Pad ❯