• PHP Video Tutorials

PHP - Ds Map get() Function


Advertisements

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

Useful Video Courses


Video

PHP Online Training

45 Lectures 9 hours

Malhar Lathkar

Video

Become PHP Facebook Developer: Password-Less Authentication

34 Lectures 4 hours

Syed Raza

Video

Ultimate PHP & MySQL Web Development Course & OOP Coding

84 Lectures 5.5 hours

Frahaan Hussain

Video

Learn PHP from Scratch

17 Lectures 1 hours

Nivedita Jain

Video

E Commerce Website Development In PHP With PDO

100 Lectures 34 hours

Azaz Patel

Video

PHP in Telugu

43 Lectures 5.5 hours

Vijay Kumar Parvatha Reddy

Advertisements