In PHP, you can use the "array_pop" function to delete the last element in the array. The syntax is "array_pop(array)". The parameter "array" represents the array, and the return value is the last value of the array, but If the array is empty, or is not an array, NULL will be returned.
Recommended: "PHP Tutorial"
Remove the last element from the php array
array_pop definition and usage
array_pop() function deletes the last element in the array.
Syntax
array_pop(array)
Parameters
array required. Specifies an array.
Technical details
Return value: Returns the last value of the array. If the array is empty, or is not an array, NULL will be returned.
PHP Version: 4
Example
Delete the last element in the array:
<?php $a=array("red","green","blue"); array_pop($a); print_r($a); ?>
Running result:
Array ( [0] => red [1] => green )
The above is the detailed content of How to remove the last element from php array. For more information, please follow other related articles on the PHP Chinese website!