The
array_pop() array function in PHP will remove the last element in an array and the result is the adjusted array with the last element removed. You can easily access the last value removed from array as well as the resulting array, as shown below in the code example.
<?php
$targetArray = array("Sara","Cindy","Julie","Megan");
$lastElement = array_pop($targetArray);
echo "$lastElement <hr />";
foreach ($targetArray as $key => $value) {
echo "$key - <strong>$value</strong><br />";
}
?>
Megan
0 - Sara
1 - Cindy
2 - Julie