Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

array_pop()

array_pop() removes the last inserted element in an array, and returns it. The original array is reduced by one element.

array_pop() removes the last element and the last key of the array. The operation is quick, O(1) of big O complexity.

array_pop() is the opposite operation of array_push() and the [] append operator. With these functions, it is possible to build FIFO stacks.

array_pop() returns the poped value, and modifies the source array in place.

<?php

    $array = [1, 2, 3, 4, 5];
    echo array_pop($array); // 5
    // $array == [1, 2, 3, 4];

    $array = [1, 2, 3, 4];
    $array[] = -2;
    echo array_pop($array); // -2
    
?>

Documentation

See Also