What is the function of phparray_shift? In php, the array_shift () function is used to delete the first element in the array and return the value of the deleted element. This article describes in detail the usage and definition of the phparray_shift () function. if you are interested, you can take a look and hope to help you.
What is the role of the php array_shift () function?
In php, the array_shift () function is used to delete the first element in the array and return the value of the deleted element. This article describes in detail the usage and definition of the php array_shift () function. if you are interested, you can take a look and hope to help you.
Definition and usage
The array_shift () function deletes the first element in the array and returns the value of the deleted element. If the array is empty, NULL is returned .. If the key name is a number, all elements will get a new key name, starting from 0 and increasing with 1 (refer to the sample code below), the text key value remains unchanged.
Syntax
array_shift(array)
The parameter array is a specified array and must be specified.
Example 1
Use the php array_shift () function to delete the first element in the $ stack array and return the deleted element. the code is as follows:
Code running output result:
The code above deletes the first element in the $ stack array and assigns the element orange to $ fruit.
Example 2
Use the php array_shift () function to delete an array with a number key name. The code is as follows:
"red",1=>"green",2=>"blue");echo array_shift($a);print_r ($a);?>
Code running output result:
We can see that the key name of the original element "green" is "1", but after the array_shift () function is used, all the key names start from 0.
[Recommended related articles]
Definition and usage of php array function array_push ()
Detailed examples of array_push (), array_pop (), and array_shift () functions in php
The above is a detailed explanation of the php array_shift () function: delete the details of the first element in the array. For more information, see other related articles in the first PHP community!