PHP array_unshift() function

This function inserts new array elements at the beginning of the array. We can insert one or more elements in an array.

Syntax

array_unshift(array, value1 , value2, value3);
The array is a required parameter and at least one value is required to insert.

Example

<?php
    $arr = array("car", "bus", "truck");
    $new_arr = array_unshift($arr, "cycle", "bike");
    print_r($new_arr); 
    echo '<br/>';
    print_r($arr);
?>		

Output :

5
Array ( [0] => cycle [1] => bike [2] => car [3] => bus [4] => truck )



Related PHP Functions

PHP array_reverse() function
PHP array_diff() function
PHP array_key_exists() function
PHP array_push() function
PHP array_search() function
PHP class_exists() function
PHP curl_setopt() function
PHP die() function
PHP dirname() function
PHP each() function
PHP explode() function
PHP file_exists() function
PHP function_exists() function
PHP getenv() function
PHP is_readable() function
PHP ksort() function
PHP mkdir() function
PHP ob_start() function
PHP parse_url() function
PHP str_repeat() function
PHP substr() function




Read more articles


General Knowledge



Learn Popular Language