Home >Backend Development >PHP Problem >How to remove the last element from php array

How to remove the last element from php array

藏色散人
藏色散人Original
2020-07-28 09:47:183006browse

In PHP, you can use the "array_pop" function to delete the last element in the array. The syntax is "array_pop(array)". The parameter "array" represents the array, and the return value is the last value of the array, but If the array is empty, or is not an array, NULL will be returned.

How to remove the last element from php array

Recommended: "PHP Tutorial"

Remove the last element from the php array

array_pop definition and usage

array_pop() function deletes the last element in the array.

Syntax

array_pop(array)

Parameters

array required. Specifies an array.

Technical details

Return value: Returns the last value of the array. If the array is empty, or is not an array, NULL will be returned.

PHP Version: 4

Example

Delete the last element in the array:

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

Running result:

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

The above is the detailed content of How to remove the last element from php array. 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