Example 1 — Get the Last Value of an Array
The simplest use of end() is to read the final element of a list of values.
<?php
$fruits = ["apple", "banana", "cherry"];
$last = end($fruits);
echo $last; How It Works
- The array $fruits holds three strings.
- end() moves the internal pointer to the last element, which is "cherry".
- The value of that element is returned and saved in $last.
- echo prints the value, so the page shows cherry.

