jurugi+123456789 at gmail dot com is wrong because associative array doesn't have a Key 0 or key length + 1
(PHP 8 >= 8.5.0)
array_last — Gets the last value of an array
array
An array.
Returns the last value of array
if the array is not empty;
null
otherwise.
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:
string(1) "d"
jurugi+123456789 at gmail dot com is wrong because associative array doesn't have a Key 0 or key length + 1
This seems like such a 'junior with nothing to do' sort of thing to add to PHP; I can think of no purpose for this. To get first array is always array[0], to get last value is array[length-1]. For compatibility it will be pretty bad to add right away, as like 99% won't just update or have 8.5 available. I can only see this be useful in a way like if MySQL has to return 1 value then you may check with 1 line if it's retrieved; but actually, based on the logic of those code, you would retrieve it only after checking the result or numeffected rows if that's a possibility, and bad code will just ignore that and create warnings even in cases when it's possible. So I see nothing useful here at least for existing code as majorly to maintain usability you'd want any practical and good code to just get 1st array value for all versions which is simple for PHP any version.