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

How to delete the first element in an array in php

王林
王林Original
2020-07-13 17:57:232498browse

The way PHP deletes the first element in an array is through the built-in function array_shift(). 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 in an array in php

#To delete the first element in the array, you can use the built-in function array_shift().

Related function introduction:

array_shift() function

array_shift() function is used to delete the first element in the array and return the deleted element.

Function syntax:

array_shift(array)

Return value:

Returns the value of the element removed from the array, or NULL if the array is empty.

Code implementation:

<?php
$user=array(&#39;apple&#39;,&#39;banana&#39;,&#39;orange&#39;);
$result=array_shift($user);
print_r($result);
print_r($user);
?>

Output result:

apple
array(&#39;banana&#39;,&#39;orange&#39;)

The above is the detailed content of How to delete the first element in 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