Friday, November 14, 2025
HomeLanguagesPHP | DsMap keys() Function

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:




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


Output:

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

Program 2:




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


Output:

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

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!
RELATED ARTICLES

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6889 POSTS0 COMMENTS
Ted Musemwa
7141 POSTS0 COMMENTS
Thapelo Manthata
6837 POSTS0 COMMENTS
Umr Jansen
6839 POSTS0 COMMENTS