PHP | Ds\Map last() Function
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:
- How to get the function name inside a function in PHP ?
- PHP Ds\Map sum() Function
- PHP | Ds\Map first() Function
- PHP | cos( ) Function
- PHP | Ds\Set xor() Function
- PHP | max( ) Function
- PHP | min( ) Function
- PHP | Ds\Map xor() Function
- PHP | end() Function
- PHP | abs() Function
- PHP | dir() Function
- PHP | pos() Function
- PHP | key() Function
- PHP | sin( ) Function
- PHP | Ds\Map put() 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.



