How to Remove Last Element from Array in PHP

AuthorHariom Prajapati

Pubish Date22 Jun 2022

categoryPHP

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

Comments 0

Leave a comment