This article mainly introduces the function of deleting the first element and the last element of the array in php. Friends in need can refer to the following
for Aphp array, how to delete the first element or the last element of the array? In fact, both processes can be completed through the functions array_pop and array_shift that come with PHP. Here is a detailed introduction on how to operate.
(1) Use array_pop to delete the last element of the array, for example:
$user=array('apple','banana','orange'); $result=array_pop($user); print_r($result); print_r($user);
array(' apple','banana')
(2) Use array_shift to delete the first element of the array, for example:
$user=array('apple','banana','orange'); $result=array_shift($user); print_r($result); print_r($user);
array('banana','orange')
array_splice function to delete the first element of the array, that is:
The code is as follows:$user=array_splice($user,1); //删除数组第一个元素,注意此时返回的是被删除后的新的数组
The above is the detailed content of How to delete the first and last element of an array in php. For more information, please follow other related articles on the PHP Chinese website!