php8.5
Home/ Manual/ array / functions/ array_last

array_last

PHP function Edit on GitHub ✎

(PHP 8 >= 8.5.0)

Gets the last value of an array

Description

array_last(array $array): mixed

Get the last value of the given array.

Parameters

array

An array.

Return Values

Returns the last value of array if the array is not empty; null otherwise.

Examples

Basic array_last() Usage

php
<?php
$array = [1 => 'a', 0 => 'b', 3 => 'c', 2 => 'd'];

$lastValue = array_last($array);

var_dump($lastValue);
?>

The above example will output:

output
string(1) "d"

See Also

Source: reference/array/functions/array-last.xml · from the official PHP manual (php/doc-en)