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.
#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('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!