Change language

PHP Ds / Map remove () function

Syntax:
mixed DsMap::remove ($key, $default)
Parameters:This function takes two parameters as above and described below:
  • $key:contains the key value to be removed.
  • $default:this is an optional parameter that is returned if the key is not found.
Return value:This function returns a value, which was removed.Exception:This function will throw a OutOfRangeException if the key does not exist and $default is not specified.The following programs illustrate the Ds / Map::remove() function in PHP:Example 1:  
// Announcement new map $map = new DsMap ([ 1 = > "engineer" , 2 = > "for" , 3 = > "engineer" , 4 = > "DataStructures"]); echo ( " Map Elements " );  
// Show map elements print_r ( $map ); echo ( " Removed element of the map: " );  
// Use the remove() function to remove
// value at index 3 and return it var_dump ( $map -> remove (3));  
?>
Exit:
Map Elements DsMap Object ([0] = > DsPair Object ([key] = > 1 [value] = > engineer) [1] = > DsPair Object ([key] = > 2 [value] = > for) [2] = > DsPair Object ([key] = > 3 [value] = > engineer) [3] = > DsPair Object ([key] = > 4 [value] = > DataStructures)) Removed element of the map: string (5) "engineer"
Example :  
// Declare new map $map = new DsMap ([ "a" = > "engineer" , "b" = > "for" , "c" = > "engineer" , "d" = > "DataStructures"]); echo ( " Map Elements " );  
// Show map elements print_r ( $map ); echo ( " Removed element of the map: " );  
// Use the remove() function to remove
// value at index 3 and return it var_dump ( $map -> remove ( " c " ) );  
?>
Exit:
Map Elements DsMap Object ([0] = > DsPair Object ([key] = > a [value] = > engineer) [1] = > DsPair Object ([key] = > b [value] = > for) [2] = > DsPair Object ([key] = > c [value] = > engineer) [3] = > DsPair Object ([key] = > d [value] = > DataStructures)) Removed element of the map: string (5) "engineer"
Link: https://www.php.net/manual/en/ds-map.remove.php

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method