PHP | Ds\Map keys() Function

The Ds\Map::keys() function of PHP is used to get a set of keys of the current Map instance. The order of keys in the returned set is the same as that of the order of keys in the actual Map instance.

Syntax:

Ds\Set public Ds\Map::keys ( void )

Parameter: This function does not accepts any parameter.



Return value: It returns a set of Ds\Set containing all of the keys of the specified Map instance in the same order.

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

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

Ds\Set Object
(
    [0] => 1
    [1] => 2
    [2] => 3
)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

Ds\Set Object
(
    [0] => first
    [1] => second
    [2] => third
)

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.