HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

array_last

Description

The array_last of Array for PHP gets the last value of an array.

Syntax

array_last(
    array $array
): mixed

Parameters

array

An array.

Return

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

Examples

1 · array · indexed

<?

$array =
[
    "value1",
    "value2",
    "value3"
];

$return = array_last($array);

var_export($return);
'value3'

2 · array · associative

<?

$array =
[
    "key1" => "value1",
    "key2" => "value2",
    "key3" => "value3"
];

$return = array_last($array);

var_export($return);
'value3'

3 · array · empty

<?

$array = [];

$return = array_last($array);

var_export($return);
NULL