How to delete the last element of an array in php

青灯夜游
Release: 2023-03-16 10:10:01
Original
3082 people have browsed it

Deletion method: 1. Use array_pop() to delete the last element, the syntax is "array_pop($arr);"; 2. Use array_splice() to delete the last N elements, just set the second parameter Just "-N", the syntax is "array_splice($arr,-N)".

How to delete the last element of an array in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php deletes the array at the end Several methods of elements

Method 1: Use array_pop() function to delete the last element

array_pop($array)Function deletes the last element in the array.

This function will change the original array; the return value is the last value of the array. If the array is empty or not an array, NULL will be returned.

Copy after login

How to delete the last element of an array in php

Method 2: Use the array_splice() function to delete the last few array elements

array_splice() function is used to delete the array part of the elements; set the second parameter of the array_splice() function to-Nto delete the lastNarray elements.

Copy after login

How to delete the last element of an array in php

Recommended learning: "PHP Video Tutorial"

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!

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!