Home  >  Article  >  Backend Development  >  How to delete the last array element in php

How to delete the last array element in php

王林
王林Original
2020-08-19 15:33:322515browse

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)

(Recommended learning video: php video tutorial )

Implementation code:

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

Output result:

Array ( [0] => red [1] => green )

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!

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