PHP end() Function | PHP Array Functions

The end() function sets the internal pointer of an array to its last element and returns its value. This is useful when you need to access or manipulate the last element of an array.

Key Features of end()

Syntax of end()

Syntax

mixed end(array &$array);

Example Using end()

The following example demonstrates how end() works:

Example


$array = ["PHP", "JavaScript", "Python", "Ruby"];
        
$lastElement = end($array);
echo "The last element of the array is: " . $lastElement;
        

Output

The last element of the array is: Ruby