array_last

(PHP 8 >= 8.5.0)

array_lastGets the last value of an array

Açıklama

array_last(array $array): mixed

Get the last value of the given array.

Bağımsız Değişkenler

array
An array.

Dönen Değerler

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

Örnekler

Örnek 1 Basic array_last() Usage

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

$lastValue = array_last($array);

var_dump($lastValue);
?>

Yukarıdaki örneğin çıktısı:

string(1) "d"

Ayrıca Bakınız

add a note

User Contributed Notes 1 note

up
0
php dot net at pother dot ca
15 hours ago
For PHP <= 8.4.0 :

<?php

if (! function_exists('array_last')) {
    function array_last(array $array) {
        return $array === [] ? null : $array[count($array) - 1];
    }
}

?>
To Top