The Map
class in PHP is a collection of key-value pairs. The structure of a Map
is similar to an array in terms of the
The last()
function is used to return the last key-value pair in a map.
The following is the function prototype:
Ds\Pair public Ds\Map::last()
The last()
function does not take any input parameters.
The function returns the last key-value pair in the map.
Let’s run the following code to see how the last()
function works.
<?php// Creating a Map$map = new \Ds\Map(["0" => "a","1" => "b", "2" => "c", "3" => "d", "4" => "e", "5" => "f"]);print_r($map->last());?>
In the example above, we create a simple map. Using the last()
function, we are able to directly print the last key-value pair in the map.