Getting the Last Element of an Array in PHP


Access the last element of an array without removing it.

Source Code

$fruits = ['apple', 'banana', 'cherry'];
$lastFruit = end($fruits);
echo $lastFruit; // Outputs: cherry
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments