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

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

青灯夜游
青灯夜游Original
2020-07-21 15:57:372685browse

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)

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);
?>

Output:

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

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!

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