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 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 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
Recommended Posts:
- PHP | Ds\Sequence last() Function
- PHP | Ds\Vector last() Function
- PHP | Ds\Set last() Function
- PHP | Ds\Deque last() Function
- PHP program to find the length of the last word in string
- PHP | Print the last value of an array without affecting the pointer
- Determine the first and last iteration in a foreach loop in PHP?
- How to get the last n characters of a PHP string?
- How to get last day of a month from date in PHP ?
- How to get the function name inside a function in PHP ?
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | imagecreatetruecolor() Function
- PHP | fpassthru( ) Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Imagick floodFillPaintImage() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

