Usage of array_shift function in php: [array_shift(array)]. The array_shift function is used to delete the first element in the array and return the value of the deleted element. If the array is empty, the function returns NULL.
php The array_shift function is used to delete the first element in the array and return the value of the deleted element. Its syntax is array_shift(array), and the parameter array is required. , indicating a specified array.
(Recommended tutorial: php video tutorial)
How to use the php array_shift function?
Function: Delete the first element in the array and return the value of the deleted element.
Syntax:
array_shift(array)
Parameters:
array Required. Specifies an array.
Description:
Returns the value of the element removed from the array, or NULL if the array is empty.
php array_shift() function usage example 1
<?php $a=array(0=>"西门",1=>"灭绝",2=>"无忌"); echo array_shift($a); //输出被删除的 数组元素的值 echo "<br>"; print_r ($a); //打印处理后的数组 ?>
Output:
西门 Array ( [0] => 灭绝 [1] => 无忌 )
php array_shift() function usage example 2
<?php $a=array(0=>"欧阳克",1=>"无忌",2=>"Peter_zhu"); echo array_shift($a); //输出被删除的 数组元素的值 echo "<br>"; print_r ($a); //打印处理后的数组 ?>
Output:
欧阳克 Array ( [0] => 无忌 [1] => Peter_zhu )
The above is the detailed content of How to use array_shift function in php. For more information, please follow other related articles on the PHP Chinese website!