CKTIS / PHP
end()
Move the internal array pointer to the last element and return its value.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
end(array|object &$array): mixedMove the internal array pointer to the last element and return its value. An empty array also yields false, so inspect its key to distinguish an actual false element. Store the array in a variable because the argument is passed by reference. Object arguments are deprecated since PHP 8.1.
Signature
end(array|object &$array): mixed
Example output
[[false,"last"],[false,null]]
Examples
<?php
$steps = ["first"=>1,"last"=>false]; $empty = [];
echo json_encode([[end($steps),key($steps)],[end($empty),key($empty)]]);
Result
[[false,"last"],[false,null]]