Given an array (One dimensional or multidimensional) and the task is to delete an array element based on key value.
Input: Array (  => 'G'  => 'E'  => 'E'  => 'K'  => 'S' ) Key = 2 Output: Array (  => 'G'  => 'E'  => 'K'  => 'S' )
Using unset() Function: The unset() function is used to remove element from the array. The unset function is used to destroy any other variable and same way use to delete any element of an array. This unset command takes the array key as input and removed that element from the array. After removal the associated key and value does not change.
Parameter: This function accepts single parameter variable. It is required parameter and used to unset the element.
Program 1: Delete an element from one dimensional array.
Array (  => G  => E  => E  => K  => S ) Array (  => G  => E  => K  => S )
Program 2: Delete an element from associative array.
Before delete the element
Array ( [Ankit] => Array ( [C] => 95 [DCO] => 85 ) [Ram] => Array ( [C] => 78 [DCO] => 98 ) [Anoop] => Array ( [C] => 88 [DCO] => 46 ) ) After delete the element
Array ( [Ankit] => Array ( [C] => 95 [DCO] => 85 ) [Anoop] => Array ( [C] => 88 [DCO] => 46 ) )
- PHP | Program to delete an element from array using unset() function
- How to delete last element from a map in C++
- Memory based Vs Register based addressing modes
- How to get the first element of an array in PHP?
- PHP | Second most frequent element in an array
- Removing Array Element and Re-Indexing in PHP
- PHP | Deleting an element from array using array_diff()
- PHP program to find missing element(s) from an array
- Find the index of an array element in Java
- Font scaling based on width of container using CSS
- Selecting rows in pandas DataFrame based on conditions
- PHP | MySQL Delete Query
- CSS | element+element Selector
- CSS | element > element Selector