Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

array_shift()

Remove and return the first element, modifying the array passed by reference.

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

Syntax

array_shift(array &$array): mixed

Remove and return the first element, modifying the array passed by reference. Remaining integer keys are renumbered from zero, while string keys survive. An empty array returns null. Avoid using the old integer keys as stable identifiers after removing a leading element.

Signature

array_shift(array &$array): mixed

Example output

["A",{"0":"B","late":"C"}]

Examples

<?php
$jobs = [4=>'A', 8=>'B', 'late'=>'C'];
$first = array_shift($jobs);
echo json_encode([$first, $jobs]);

Result

["A",{"0":"B","late":"C"}]

Sources