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 ) )
- Difference between Preemptive Priority based and Non-preemptive Priority based CPU scheduling algorithms
- Difference between Memory based and Register based Addressing Modes
- Difference between Primary key and Super key
- PHP | Program to delete an element from array using unset() function
- How to search by key=>value in a multidimensional array in PHP ?
- How to loop through an associative array and get the key in PHP?
- How to search by multiple key => value in PHP array ?
- How to remove a key and its value from an associative array in PHP ?
- How to create an array with key value pairs in PHP?
- How to check a key exists in an array in PHP ?
- How to change an element color based on value of the color picker value using onclick?
- How to repeat HTML element multiple times using ngFor based on a number?
- How to change an element color based on value of the color picker value on click?
- How to delete last element from a map in C++
- How to push a value based on matched value in PHP ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.