php8.5
Home/ Manual/ ds / map/ Ds\Map::last

Ds\Map::last

PHP function Edit on GitHub ✎

(PECL ds >= 1.0.0)

Returns the last pair of the map

Description

Ds\Map::last(): Ds\Pair

Returns the last pair of the map.

Parameters Parameters

Return Values

The last pair of the map.

Errors/Exceptions

UnderflowException if empty.

Examples

Ds\Map::last() example

php
<?php
$map = new \Ds\Map(["a" => 1, "b" => 2, "c" => 3]);
var_dump($map->last());
?>

The above example will output something similar to:

output
object(Ds\Pair)#2 (2) {
  ["key"]=>
  string(1) "c"
  ["value"]=>
  int(3)
}

Source: reference/ds/ds/map/last.xml · from the official PHP manual (php/doc-en)