How to delete the last array element in php

王林
Release: 2023-03-04 19:10:01
Original
2516 people have browsed it

How to delete the last array element in php: You can use the built-in function array_pop() to delete. The array_pop() function can delete the last element in the specified array and will return null if the array is empty or not an array.

How to delete the last array element in php

array_pop() function removes the last element in the array and returns the last value of the array. If the array is empty, or is not an array, NULL will be returned.

(Recommended tutorial: php graphic tutorial)

Grammar:

array_pop(array)
Copy after login

(Recommended learning video: php video tutorial )

Implementation code:

<?php
$a=array("red","green","blue");
array_pop($a);
print_r($a);
?>
Copy after login

Output result:

Array ( [0] => red [1] => green )
Copy after login

The above is the detailed content of How to delete 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template