• PHP Video Tutorials

PHP - Ds Map get() Function



Ds\Map::get() function can return the value for a given key.

Syntax

public mixed Ds\Map::get( mixed $key [, mixed $default ] )

Ds\Map::get() function can return the value for a given key or an optional default value if the key can't found.

Ds\Map::get() function can return the value mapped to the given key, or the default value is provided and the key can't be found in the map.

Ds\Map::get() function can throw OutOfBoundsException if the key can't be found, and the default value was not provided.

Example 1

<?php  
   $map = new \Ds\Map([1 => 10, 2 => 20, 3 => 30, 4 => 40, 5 => 50]);  
  
   var_dump($map->get(1)); 
   var_dump($map->get(2)); 
   var_dump($map->get(4)); 
   var_dump($map->get(6, 60)); 
?> 

Example-2

<?php  
   $map = new \Ds\Map(["x" => "Tutorials", "y" => "Point", "z" => "India"]);  
  
   var_dump($map->get("x")); 
   var_dump($map->get("y")); 
   var_dump($map->get("z")); 
   var_dump($map->get("w", "Tutorix")); 
?> 
php_function_reference.htm
Advertisements