Are there any alternative functions to array_pop that do not remove the last element from the array?

The issue is that the array_pop function in PHP removes the last element from an array, which may not be desired in certain situations where you want to access the last element without removing it. To solve this issue, you can use the end function to retrieve the last element of an array without modifying the original array.

// Using end() function to get the last element of an array without removing it
$array = [1, 2, 3, 4, 5];
$lastElement = end($array);

echo $lastElement; // Output: 5