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

How to delete the first element in an array in php

王林
Release: 2023-03-02 14:14:01
Original
2538 people have browsed it

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)
Copy after login

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);
?>
Copy after login

Output result:

apple
array(&#39;banana&#39;,&#39;orange&#39;)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template