Home > Backend Development > PHP Tutorial > Detailed explanation of the php array_pop() function to delete the last element in the array

Detailed explanation of the php array_pop() function to delete the last element in the array

怪我咯
Release: 2023-03-08 06:24:01
Original
3523 people have browsed it

php array_pop() function usage and definition?

array_pop() function is one of the PHP Array array functions. Its function is to delete the last element in the array (pop it off the stack).

PS: Stack, also known as stack, is a linear table with limited operations. The restriction is that insertion and deletion operations are only allowed at one end of the table. This end is called the top of the stack, and the other end is called the bottom. Inserting a new element into a stack is also called pushing, pushing or pushing the stack. It is to put the new element on top of the top element of the stack, making it the new top element of the stack; deleting it from a stack Elements are also called pop or pop off the stack. It deletes the top element of the stack and makes its adjacent elements become the new top elements of the stack.

After understanding the function of php array_pop() function, let’s take a look at its syntax:

Syntax

array_pop(array)
Copy after login

Detailed explanation of parameters:

The array_pop() function has only one parameter array, which specifies which array to delete elements from. There will be examples below to demonstrate the return value of the

array_pop() function

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

Example

Use the array_pop() function to delete the last element in the array and return the deleted element. The code is as follows:

<?php
$a=array("red","green","blue");
$pop=array_pop($a);
print_r($a);
echo $pop;
?>
Copy after login

Code Run output result:

Detailed explanation of the php array_pop() function to delete the last element in the array

The above example uses the array_pop() function to delete the last element "blue" in the array $a. When we print out the array $a , there are only two elements in it, and the deleted element is assigned to $pop

[Related article recommendations]

Detailed explanation of php array_shift() function: delete the first element in the array

Detailed explanation of array_push(), array_pop() and array_shift() function usage examples in php

The above is the detailed content of Detailed explanation of the php array_pop() function to delete the last element in the 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