PHP 8.5.0 RC 2 available for testing

array_last

(PHP 8 >= 8.5.0)

array_lastGets the last value of an array

Опис

array_last(array $array): mixed

Get the last value of the given array.

Параметри

array

An array.

Значення, що повертаються

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

Приклади

Приклад #1 Basic array_last() Usage

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

$lastValue = array_last($array);

var_dump($lastValue);
?>

Поданий вище приклад виведе:

string(1) "d"

Прогляньте також

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top