Home >Backend Development >PHP Problem >How to remove the last element of an array in php
php method to remove the last element of the array: You can use the built-in function array_pop() to achieve this. The array_pop() function can delete the last element in the array and return it, or NULL if the array is empty or not an array.
#The built-in function array_pop() in php can easily solve our problem. This function removes the last element from the array and returns NULL if the array is empty or not an array.
(Recommended learning tutorial: php video tutorial)
Function syntax:
array_pop(array)
(Recommended related tutorial: php graphic tutorial)
Implementation code:
<?php $a=array("red","green","blue"); array_pop($a); print_r($a); ?>
Run result:
Array ( [0] => red [1] => green )
The above is the detailed content of How to remove the last element of an array in php. For more information, please follow other related articles on the PHP Chinese website!