Home > Article > Backend Development > How to delete the first element in an array in php
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)].
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('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 in an array in php. For more information, please follow other related articles on the PHP Chinese website!