How to Remove Last Element from Array in PHP


In this tutorial we will see that how to remove Last element from array in PHP.


In this tutorial we will take two examples single dimensional array and multi dimensional array from which we will remove Last element from array in PHP using array_pop() function.

1) How to remove Last element from single dimensional array in PHP.

<?php

    $SingleDimensionalArrays = ["w3school""teknowize""tutorialpoint"];

    array_pop($SingleDimensionalArrays);

  echo "<pre>";

    print_r($SingleDimensionalArrays);

?> 


Output

 

2) Remove Last element from multi dimensional array in PHP.

<?php

    $online_tutorial = [

        [ "id" => 1"website" => "w3school"],

        [ "id" => 2"website" => "teknowize"],

        [ "id" => 3"website" => "tutorialpoint"],

    ];

    array_pop($online_tutorial);

  echo "<pre>";

    print_r($online_tutorial);

?> 


Output


Related Topics