Home  >  Article  >  Backend Development  >  How to delete the first element of an array in php

How to delete the first element of an array in php

王林
王林Original
2020-08-20 13:14:243190browse

How to delete the first element of an array in php: You can use the built-in function array_shift() to achieve this. The array_shift() function is used to delete the first element in the array and return the deleted element, or null if the array is empty.

How to delete the first element of an array in php

array_shift() function is used to delete the first element in the array and return the deleted element, or NULL if the array is empty.

(Recommended tutorial: php graphic tutorial)

If the key name is numeric, all elements will get a new key name, starting from 0 and ending with 1 increment.

Grammar:

array_shift(array)

(Learning video recommendation: php video tutorial)

Implementation code:

$user=array('apple','banana','orange');
$result=array_shift($user);
print_r($result);
print_r($user);

Output result:

apple
array('banana','orange')

The above is the detailed content of How to delete the first element of an array in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn