Home » PHP

PHP array_pop() function with Example

PHP array_pop() function: Here, we are going to learn about the array_pop() function with example in PHP.
Submitted by IncludeHelp, on February 15, 2019

PHP array_pop() function

array_pop() function is used to delete/pop last element from the array.

Syntax:

    array_pop(array);

Here, array is the input array, function will delete last element from it.

Examples:

    Input:
    //initial array is
    $arr = array(100, 200, 300, 10, 20, 500);

    //deleting elements
    array_pop($arr);
    array_pop($arr);
    array_pop($arr);
   
    Output:
    Array
    (
        [0] => 100
        [1] => 200
        [2] => 300
    )

PHP code to delete elements from an array using array_pop() function

<?php
    $arr = array(100, 200, 300, 10, 20, 500);
    
    array_pop($arr);
    array_pop($arr);
    array_pop($arr);
    
    print("array after removing elements...\n");
    print_r($arr);
?>

Output

array after removing elements...
Array
(
    [0] => 100
    [1] => 200
    [2] => 300
)





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.