How to Array Find Last Match in PHP?

03-Apr-2023

.

Admin

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...

#PHP