Home  >  Article  >  Backend Development  >  How to remove the last element from an array in php

How to remove the last element from an array in php

藏色散人
藏色散人Original
2021-06-24 11:30:442126browse

php method to remove the last element in the array: first create a PHP sample file; then define an array; finally delete the last element in the array through the array_pop function.

How to remove the last element from an array in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How does php remove the last element in the array?

array_pop() function

Deletes the last element in the array.

Returns null if the array is empty.

Example:

<?php
$test_arr = array (
    "name" => "jeanphorn",
    "skill" => "programming",
    "hobby" => "swimming",
);
echo array_pop($test_arr). "\n"; 
print_r($test_arr);
?>

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to remove the last element from 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