ItSolutionStuff.com

How to Remove Last Element from Array in PHP?

By Hardik Savani • May 14, 2024
PHP

This example is focused on how to remove last element from array in php. We will look at example of remove last item from array in php. if you want to see example of php remove last element from array then you are a right place. i would like to show you php remove last item from array. Let's see bellow example php remove last n element from array.

Let's see simple two example single dimensional array and multi dimensional array how to remove last item from array using php array function call array_pop(). array_pop() will helps to remove last key from php array.

Example 1:

index.php

<?php

$myArray = ["Apple", "Banana", "Mango"];

array_pop($myArray);

print_r($myArray);

?>

Output:

Array

(

[0] => Apple

[1] => Banana

)

Example 1:

index.php

<?php

$students = [

[ "id" => 1, "name" => "Hardik"],

[ "id" => 2, "name" => "Haresh"],

[ "id" => 3, "name" => "Naresh"],

];

array_pop($students);

print_r($students);

?>

Output:

Array

(

[0] => Array

(

[id] => 1

[name] => Hardik

)

[1] => Array

(

[id] => 2

[name] => Haresh

)

)

i hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Reset Array Keys in PHP?

Read Now →

Laravel 5 manual pagination with array example

Read Now →

How to Remove Specific Element by Value from Array in PHP?

Read Now →

How to Remove undefined Value from Array in JQuery?

Read Now →

How to Get Maximum Key Value of Array in PHP?

Read Now →

How to Remove Empty Values from Array in PHP?

Read Now →

How to Add Prefix in Each Key of PHP Array?

Read Now →

How to Get Minimum Key Value of Array in PHP?

Read Now →

How to Remove Null Values from Array in PHP?

Read Now →

How can Make an Array from the Values of Another Array's Key Value?

Read Now →

How to Merge Two Array with Same Keys without Loop in PHP?

Read Now →