PHP array_shift() is an inbuilt function that removes the first element from an array and returns the value of a removed item. All the numerical array keys will be modified to start the counting from zero while the literal keys won’t be touched. If an array is empty, then the Null is returned.

PHP Array Shift Example

See the syntax of PHP array_shift() function.

array_shift(array)

An array parameter is required, and it specifies an array.

See the below code example.

<?php

// app.php

$data = ['Apple', 'Microsoft', 'Amazon', 'Alphabet', 'Facebook'];
echo array_shift($data)."\n";
print_r($data);

#php #array_shift

PHP Array Shift Example | PHP array_shift() Function Tutorial
1.40 GEEK