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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!



