Name

array_unshift()

Synopsis

    int array_unshift ( array &arr, mixed var [, mixed ...] )

The array_unshift() function takes an array and a new value as its only parameter, and pushes that value onto the start of the array, before all the other elements. This is the opposite of the array_shift() function.

    $firstname = "Johnny";
    $names = array("Timmy", "Bobby", "Sam", "Tammy", "Joe");
    array_unshift($names, $firstname);
    // first is Johnny, last is Joe

Get PHP in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.