How to Get Last Element of Array in 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
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Parse JSON Array in Python?
- Laravel Blade Check if Array Key Exists Example
- PHP Explode Every Character into Array Example
- PHP Remove Element from Array by Value Example
- How to Reset Array Keys in PHP?
- How to Convert XML File to Array in PHP?
- PHP Multidimensional Array Search By Value Example
- PHP Check If Array Is Multidimensional or Not
- How to Remove Specific Element by Value from Array in PHP?
- How to Get Maximum Key Value of Array in PHP?
- How to Remove Empty Values from Array in PHP?
- How to Add Prefix in Each Key of PHP Array?
- How to Get Minimum Key Value of Array in PHP?
- How to Remove Null Values from Array in PHP?