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

How to remove the last element of an array in php

王林
王林Original
2020-08-26 14:28:383516browse

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)

(Recommended related tutorial: php graphic tutorial)

Implementation code:

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

Run result:

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

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!

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