The Wayback Machine - https://web.archive.org/web/20230422123539/https://www.geeksforgeeks.org/php-dsmap-first-function/
Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

PHP | Ds\Map first() Function

Improve Article
Save Article
Like Article
author
gopaldave
scholar
1293 published articles
Improve Article
Save Article
Like Article

The Ds\Map::first() function of PHP Ds\Map class is used to get the first key-value pair from the Map instance.

Syntax:

Ds\Pair public Ds\Map::first ( )

Parameters: This function does not accepts any parameter.

Return value: It returns a pair of type Ds\Pair which is the first key-value pair from the Map instance. That is the key-value pair present at the front of the Map instance.

Below programs illustrate the Ds\Map::first() function in PHP:

Program 1:




<?php
// PHP program to illustrate first() function
  
$map = new \Ds\Map([1 => "Geeks", 2 => "for"
                                3 => "Geeks"]);
  
print_r($map->first());
  
?>

Output:

Ds\Pair Object
(
    [key] => 1
    [value] => Geeks
)

Program 2:




<?php
// PHP program to illustrate first() function
  
$map = new \Ds\Map(["first" => "Geeks", "second" => "for"
                                "third" => "Geeks"]);
  
print_r($map->first());
  
?>

Output:

Ds\Pair Object
(
    [key] => first
    [value] => Geeks
)

Reference: http://php.net/manual/en/ds-map.first.php

My Personal Notes arrow_drop_up
Last Updated : 20 Aug, 2019
Like Article
Save Article
Similar Reads