Two removal methods: 1. Use the array_pop() function to delete elements at the end of the array, with the syntax "array_pop ($arr)"; 2. Use the array_splice() function to delete part of the array elements. Just set the second parameter to "-1", the syntax is "array_splice($arr,-1)".
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, DELL G3 computer
Method 1: Use array_pop() Function
array_pop() function is used to delete elements at the end of the array.
Output result:
#Method 2: Use array_splice() function
array_splice() function To delete part of the array elements; set the second parameter of the array_splice() function to -1 to delete the last array element.
Example:
Output result:
Recommended learning:php training
The above is the detailed content of How to remove the last array element in php. For more information, please follow other related articles on the PHP Chinese website!