#PHP How to delete the first element of an array?
In PHP, you can delete the first element of the array by using the "array_shift()" function. The function of this function is to move the unit at the beginning of the array out of the array. Its syntax is "array_shift($array)" ”, its parameter $array represents the input array, and the return value is the removed element value.
Sample code
Result
Array ( [0] => banana [1] => apple [2] => raspberry )
$arr[$k]); unset($arr[$k]); return $r; } // test it on a simple associative array $arr = array('x'=>'ball','y'=>'hat','z'=>'apple'); print_r($arr); print_r(array_kshift($arr)); print_r($arr); ?> Output: Array ( [x] => ball [y] => hat [z] => apple ) Array ( [x] => ball ) Array ( [y] => hat [z] => apple
Recommended tutorial: "PHP"
The above is the detailed content of How to delete the first element of an array in PHP?. For more information, please follow other related articles on the PHP Chinese website!