Home > Backend Development > PHP Problem > How to remove the last element of an array in php

How to remove the last element of an array in php

王林
Release: 2023-03-05 09:22:02
Original
3564 people have browsed it

php method to remove the last element of the array: You can use the built-in function array_pop() to achieve this. The array_pop() function can delete the last element in the array and return it, or NULL if the array is empty or not an array.

How to remove the last element of an array in php

#The built-in function array_pop() in php can easily solve our problem. This function removes the last element from the array and returns NULL if the array is empty or not an array.

(Recommended learning tutorial: php video tutorial)

Function syntax:

array_pop(array)
Copy after login

(Recommended related tutorial: php graphic tutorial)

Implementation code:

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

Run result:

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

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