How to Array Find Last Match in PHP?
Hi Dev,
This post will give you example of how to array find last match in php. This article we will implement php end() function use array find last match. This post will give you simple example of php array find last match element. I would like to share with you get the last element of an array in php. you will do the following things for PHP find last value in an array.
The end() function changes the internal pointer of an array to point to the last element and returns the value of the last element. It's easy to get the last element of a simple numerical array.
Example 1:
index.php
<?php
$myArray = ['Ram', 'Shita', 'Geeta'];
// Get array find last match.
$lastMatch = end($myArray);
print_r($lastMatch);
?>
Output:
Geeta
Example 2:
index.php
<?php
$myArray = ['Adam', 'Monty', 'James', 'Roy'];
// Get array find last match.
$lastMatch = end($myArray);
print_r($lastMatch);
?>
Output:
Roy
I hope it could help you...
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example