#PHP How to remove an element from an array?
In PHP, you can use the "array_shift()" function to remove an element from the array. This function will move the unit at the beginning of the array out of the array. Its syntax is "array_shift(array)", and its parameter array Indicates the array to be operated on, and the return value is the removed value. This function will directly operate on the array.
array_shift() Shifts the first element of array out and returns it as the result, decrements the length of array by one and shifts all other elements forward one position. All numeric key names will be changed to count from zero, and text key names will remain unchanged.
Code Example
<?php $stack = array("orange", "banana", "apple", "raspberry"); $fruit = array_shift($stack); print_r($stack); ?>
The above routine will output:
Array ( [0] => banana [1] => apple [2] => raspberry )
And orange is assigned to $fruit.
Recommended tutorial: "PHP Tutorial"
The above is the detailed content of How to remove an element from an array in PHP?. For more information, please follow other related articles on the PHP Chinese website!