How to remove last element of an array in PHP

How to remove last element of an array in PHP, We can remove last element of an array using array_pop function in php. First we are using an array with sample values, then we are assigning it to an $array variable, before applying the function we are printing array with print_r function surrounded with pre tags, this pre tag will display an array in human readable manner. After that we are using array_pop by simply passing the array, after applying the function we are again printing the array surrounded with pre tags.

<?php
$array = array('hi', 'this', 'is', 'an', 'array');
echo "<pre>";
print_r($array);

array_pop($array);
print_r($array);
echo "</pre>";
?>

Vivek Vengala
 

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply:

x

Join My Facebook Group to Receive Coding Tutorial for Free

email-subsribe