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-03 07:28:01
Original
3086 people have browsed it

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

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:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template