+

PHP Ds / Map get () function

Syntax:
mixed public DsMap::get (mixed $key [, mixed $default])
Parameter:This function takes two parameters as above and described below:
  • $key:contains the key whose value will be returned.
  • $default:this is an optional parameter that is returned if the key is not found.
Returned value:this function returns the value associated with the given key, or returns a default value if the key is not found.The following programs illustrate the Ds / Map::get()function in PHP:Program 1:
// PHP illustration program get()
// Ds / map function 
// Create a map $map = new DsMap ([ 1 = > 10, 2 = > 20, 3 = > 30, 4 = > 40, 5 = > fifty]);  
// Use the function Ds / Map::get() var_dump ( $map -> get ( one)); var_dump ( $map -> get (3)); var_dump ( $map -> get (5)); var_dump ( $map -> get (7, 100));  
?>
Exit:
int (10 ) int (30) int (50) int (100)
Program 2: < ? php  
// Create a map $map = new DsMap ([ "a" = > "Geeks" , " b " = > " for " , "c" = > " Geeks "]);  
// Use the function Ds / Map::get() var_dump ( $map -> get ( "a" )); var_dump ( $map -> get ( "b" )); var_dump ( $map -> get ( "c" )); var_dump ( $map -> get ( "d" , "GeeksforGeeks" ));  
?>
Exit:
string (5 ) "Geeks" string (3) "for" string (5) "Geeks" string (13) "GeeksforGeeks"
Link: https://www.php.net/manual/en/ds-map.get.php
Get Solution for free from DataCamp guru