Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

array_pop()

Remove and return the last value of an array, modifying the array passed by reference.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

array_pop(array &$array): mixed

Remove and return the last value of an array, modifying the array passed by reference. This provides a simple stack operation. An empty array returns null, so the return value alone cannot distinguish an empty stack from a stored null. Check the size first if that distinction matters.

Signature

array_pop(array &$array): mixed

Example output

[null,"B",null,[]]

Examples

<?php
$stack = ['B', null];
$first = array_pop($stack);
$second = array_pop($stack);
echo json_encode([$first, $second, array_pop($stack), $stack]);

Result

[null,"B",null,[]]

Sources