clock  Mon - Sun 8.00 AM - 8.00 PM
fb
instagram
play store
pinterest

How to Remove Last Element from Array in PHP

writter  Hariom Prajapati
Date  22 Jun 2022
Language  PHP
How to Remove Last Element from Array in PHP

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 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

php

 

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

php