Open In App

PHP | Ds\Map last() Function

Last Updated : 21 Aug, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The Ds\Map::last() function in PHP is used to find and get the last key-value pair from a Map object. If the map is empty then this function throws an exception. Syntax:
Ds\Pair public Ds\Map::last ( void )
ParameterDs\Pair: It does not accepts any parameter. Return value: This function returns the last key-value pair from the Map object. If the Map object is empty then this function raises UnderflowException. Below program illustrate the Ds\Map::last() function in PHP: Program 1: php
<?php
// PHP program to illustrate the last()
// function of Ds\map

// Creating a Map
$map = new \Ds\Map(["1" => "Geeks", 
            "2" => "for", "3" => "Geeks"]);

// Print last key-value pair
print_r($map->last());

?>
Output:
Ds\Pair Object
(
    [key] => 3
    [value] => Geeks
)
Program 2: php
<?php
// PHP program to illustrate the last()
// function of Ds\map

// Creating a Map
$map = new \Ds\Map(["1" => "10", 
            "2" => "20", "3" => 30]);

// Print last key-value pair
print_r($map->last());

?>
Output:
Ds\Pair Object
(
    [key] => 3
    [value] => 30
)
Reference: http://php.net/manual/en/ds-map.last.php

Next Article

Similar Reads