Name

array_shift()

Synopsis

    mixed array_shift ( array &arr )

The array_shift() function takes an array as its only parameter, and returns the value from the front of the array while also removing it from the array. For example:

    $names = array("Johnny", "Timmy", "Bobby", "Sam", "Tammy", "Joe");
    $firstname = array_shift($names); // "Johnny"
    var_dump($names);
    // Timmy, Bobby, Sam, Tammy, Danny, and 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.