How to remove the last array element in php

青灯夜游
Release: 2023-03-12 17:12:01
Original
3119 people have browsed it

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)".

How to remove the last array element in php

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.

Copy after login

Output result:

How to remove the last array element in php

#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:

Copy after login

Output result:

How to remove the last array element in php

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!