More

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

×

TOP TOPICS

Road map for web development 2022 What is git and git hub How to create a Google logo using HTML and CSS What is .htaccess file and how to use it Most important HTML5 interview questions PHP CRUD operations How to send mail using PHP Insert and fetch image using PHP How to dowload pdf using PHP How to export data in Excel using Laravel Import excel data in database using laravel How to send mail in Laravel 8 Laravel 8 CRUD Operation Laravel 8 Image Upload and Fetch Tutorial Example Laravel 8 CRUD operation using DB Laravel 8 CRUD Operation using resource controller Date Validations Using jquery Datepicker How to reset or clear a form using JavaScript Form validation in Laravel 8 How to download pdf file using Laravel 8 dompdf How to Toggle Password Visibility Using JavaScript PHP CRUD Operation Using Ajax and Jquery Get Yesterday and Tomorrow Date in PHP How to disable text selection using CSS and Jquery How to Get Previous Month and Next month date from Date in PHP Laravel CRUD Operation Using Ajax and Jquery How to find numbers from string in PHP How to Convert String Date to Date Format in PHP How to calculate age from dob column using mysql Rotate image using JQuery animate() method Allow Only Numbers in a Text Box using jQuery How To connect SSH using PHP? Radio buttons value using GET method in PHP How to get X and Y position on click event using jQuery Delete Confirmation Message using JavaScript Select2 DropDown With Validation using Bootstrap 4 How to Zoom an Image on Mouse Hover using CSS How to Remove First Element from Array in PHP How to Remove Last Element from Array in PHP E-Signature Pad using jQuery, Ajax and PHP PHP Contact Form with Google reCAPTCHA How to update profile image in Laravel using Ajax How to get X and Y position of an element using jQuery How to disable a anchor tag in HTML using CSS, JS and jQuery check if atleast one checkbox is checked or not using jQuery How can we count number of rows in a table using jQuery How can we count child elements inside a div using jQuery How to use radio button on change event in jQuery How to get checked radio button value by name using jQuery How to count the number of character in a string using jQuery How to add modal popup in PHP using jQuery?