Home >Backend Development >PHP Problem >How to delete the last element of an array in php?
In PHP, you can use the array_pop() function to delete the last element of the array; the syntax is "array_pop(array)". This function returns the last value of the array, or NULL if the array is empty or not an array.
array_pop() function deletes the last element in the array. [Related tutorial recommendations: PHP tutorial]
Syntax
array_pop(array)
Parameters:
array Required. Specifies an array.
Return value:
Returns the last value of the array. If the array is empty, or is not an array, NULL will be returned.
Example:
<?php $user=array('apple','banana','orange'); $result=array_pop($user); print_r($result); echo "<br>"; print_r($user); ?>
Output:
orange Array ( [0] => apple [1] => banana )
The above is the detailed content of How to delete the last element of an array in php?. For more information, please follow other related articles on the PHP Chinese website!