◐ Shell
clean mode source ↗

PHP: array_last - Manual

(PHP 8 >= 8.5.0)

array_lastGets the last value of an array

Description

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

Example #1 Basic array_last() Usage

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

$lastValue = array_last($array);

var_dump($lastValue);
?>

The above example will output:

See Also

Found A Problem?

sunny_reitgassl at hotmail dot de

2 months ago

For PHP < 8.5.0 && >= 7.3.0:

if (! function_exists("array_last")) {
    function array_last(array $array) {
        return $array ? $array[array_key_last($array)] : null;
    }
}