ItSolutionStuff.com

How to Get Last Element of Array in PHP?

By Hardik Savani • May 14, 2024
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...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Parse JSON Array in Python?

Read Now →

Laravel Blade Check if Array Key Exists Example

Read Now →

PHP Explode Every Character into Array Example

Read Now →

PHP Remove Element from Array by Value Example

Read Now →

How to Reset Array Keys in PHP?

Read Now →

How to Convert XML File to Array in PHP?

Read Now →

PHP Multidimensional Array Search By Value Example

Read Now →

PHP Check If Array Is Multidimensional or Not

Read Now →

How to Remove Specific Element by Value from Array in PHP?

Read Now →

How to Get Maximum Key Value of Array in PHP?

Read Now →

How to Remove Empty Values from Array in PHP?

Read Now →

How to Add Prefix in Each Key of PHP Array?

Read Now →

How to Get Minimum Key Value of Array in PHP?

Read Now →

How to Remove Null Values from Array in PHP?

Read Now →