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

How to use array_pop function in php

藏色散人
藏色散人Original
2019-05-24 15:10:484304browse

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)

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);  //打印处理之后的数组
?>

Output:

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

php array_pop() function usage example 2

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

Output:

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

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!

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