Home >Backend Development >PHP Problem >How to remove the first element from php array
In PHP, you can use the "array_shift()" function to remove the first element in the array. The syntax of this function is "array_shift(array)". Its parameter "array" represents the array, and the return value is from the array. The value of the deleted element.
php array removes the first element
Definition and usage
array_shift() function Removes the first element from the array and returns the value of the removed element.
Note: If the key is numeric, all elements will get new keys, starting at 0 and increasing by 1 (see example below).
Syntax
array_shift(array)
Parameters
array required. Specifies an array.
Return value: Returns the value of the element removed from the array, or NULL if the array is empty.
Use numeric key name:
<?php $a=array(0=>"red",1=>"green",2=>"blue"); echo array_shift($a); print_r ($a); ?>
Run result:
redArray ( [0] => green [1] => blue )
For more related knowledge, please visit PHP Chinese website!
The above is the detailed content of How to remove the first element from php array. For more information, please follow other related articles on the PHP Chinese website!