How to delete the last element of an array in php?

青灯夜游
Release: 2023-03-02 19:46:01
Original
2707 people have browsed it

In PHP, you can use the array_pop() function to delete the last element of the array; the syntax is "array_pop(array)". This function returns the last value of the array, or NULL if the array is empty or not an array.

How to delete the last element of an array in php?

array_pop() function deletes the last element in the array. [Related tutorial recommendations: PHP tutorial]

Syntax

array_pop(array)
Copy after login

Parameters:

  • array Required. Specifies an array.

Return value:

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

Example:

<?php
$user=array(&#39;apple&#39;,&#39;banana&#39;,&#39;orange&#39;);
 
$result=array_pop($user);
 
print_r($result);
echo "<br>";
print_r($user);
?>
Copy after login

Output:

orange
Array ( [0] => apple [1] => banana )
Copy after login

The above is the detailed content of How to delete 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