How to remove the last element from php array

藏色散人
Release: 2023-03-03 12:00:01
Original
2962 people have browsed it

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)
Copy after login

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);
?>
Copy after login

Running result:

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

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!

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