In PHP, the end() function can be used to move the internal pointer of an array to the last element and return its value. If the array is empty, it returns NULL.
To move the internal pointer to the last element of an array, you can use the following code:
end($array);
This function moves the internal pointer to the last element of the array and returns its value. If the array is empty, it will return NULL.
$array = ["foo", "bar", "baz"];
echo end($array); // Output: "baz"
If the internal pointer is successfully moved to the last element, the end() function will return its value. If not, it will return NULL.
$array = ["foo", "bar", "baz"];
if (end($array) !== null) {
echo "The internal pointer is at the last element: " . end($array);
} else {
echo "The array is empty.";
}
By using the end() function, PHP developers can easily manipulate the array's pointer and work with the last element. We hope this article is helpful to you. For more PHP tips, keep following related tutorials.