How to Get Last Element of Array in PHP?

By Hardik Savani May 14, 2024 Category : PHP

Hello,

This article will give you an example of php array get last element value. you will learn how to get last element of array in php. This example will help you php get last key of array example. step by step explain how to get last key value of array in php.

we will use end() function to get last element of array in php. so, let's see the simple code of how to get last element value in php array.

Example:

index.php

<?php

$myArray = ["One", "Two", "Three", "Four"];

$lastElem = end($myArray);

var_dump($lastElem);

?>

Output:

string(4) "Four"

I hope it can help you...

Tags :
Shares