remove the last element from an array in PHP

remove the last element from an array in PHP

In this post we will give you information about remove the last element from an array in PHP. Hear we will give you detail about remove the last element from an array in PHPAnd how to use it also give you demo for it if it is necessary.

Use the PHP array_pop() function


You can use the PHP array_pop() function to remove an element or value from the end of an array. The array_pop() function also returns the last value of array. However, if the array is empty (or the variable is not an array), the returned value will be NULL.


Let’s check out an example to understand how this function basically works:



<?php
$sports = array("Baseball", "Cricket", "Football", "Shooting");
 
// Deleting last array item
$removed = array_pop($sports);
print_r($sports);
echo "<br>";
var_dump($removed);
?>


 

Hope this and post will helped you for implement remove the last element from an array in PHP. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

37  +    =  44

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US