Home > Backend Development > PHP Problem > How to use array_pop function in php

How to use array_pop function in php

藏色散人
Release: 2023-02-22 18:04:02
Original
4282 people have browsed it

Usage of array_pop function in php: [array_pop(array)]. The array_pop function is used to delete the last element in the array and return the last value in the array; if the array is empty or not an array, it returns null.

How to use array_pop function in php

php The array_pop function is used to delete the last element in the array. Its syntax is array_pop(array). The parameter array is required and specifies the array.

(Recommended tutorial: php video tutorial)

How to use the php array_pop function?

Function: Delete the last element in the array

Syntax:

array_pop(array)
Copy after login

Parameters:

array required. Specifies an array.

Description:

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

php array_pop() function usage example 1

<?php
$a=array("西门","灭绝");
print_r(array_pop($a)); // 打印被删除的元素
echo "<br>";
print_r($a);  //打印处理之后的数组
?>
Copy after login

Output:

灭绝
Array ( [0] => 西门 )
Copy after login

php array_pop() function usage example 2

<?php
$a=array("无忌","欧阳克","peter_zhu");
print_r(array_pop($a)); // 打印被删除的元素
echo "<br>";
print_r($a);  //打印处理之后的数组
?>
Copy after login

Output:

peter_zhu
Array ( [0] => 无忌 [1] => 欧阳克 )
Copy after login

The above is the detailed content of How to use array_pop function in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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