• PHP Video Tutorials

PHP - Ds Map remove() Function



Ds\Map::remove() function can remove and return a value by key.

Syntax

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

Ds\Map::remove() function can remove and return a value by key or return an optional default value if a key can't be found.

Ds\Map::remove() function can return a value that was removed or a default value if provided, and a key can't be found in a map.

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

Example 1

<?php  
   $map = new \Ds\Map([1 => "Tutorials", 2 => "Point", 3 => "India", 4 => "Tutorix"]);  
  
   echo("The map elements are: \n");  
   print_r($map);  
  
   echo("\n The removed element of a map: \n");  
   var_dump($map->remove(3));  
?>

Example 2

<?php  
   $map = new \Ds\Map(["a" => "Tutorials", "b" => "Point", "c" => "India", "d" => "Tutorix"]);  
  
   echo("The map elements are: \n");  
   print_r($map);  
  
   echo("\n The removed element of a map: \n");  
   var_dump($map->remove("c"));  
?>
php_function_reference.htm
Advertisements