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-23 16:09:262972browse

php method to delete the first element in the array: This can be achieved through the array_shift() function. This function is used to remove the first element from the array and returns the value of the element removed from the array or NULL if the array is empty. The specific usage method is: [array_shift($user)].

How to delete the first element in an array in php

Function introduction:

(Recommended tutorial: php tutorial)

array_shift() function Used to remove the first element from an array and returns the value of the element removed from the array, or NULL if the array is empty.

If the key is numeric, all elements will get new keys, starting at 0 and increasing by 1.

Function syntax:

array_shift(array)

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