How to remove a key and its value from an associative array in php?
Using unset() function: The unset() function is used to unset a key and its value in an associative array in php.
1. Code:
<?php
// Declare an associative array
$arr = array(
"1" => "Soltuts",
"2" => "sol",
"3" => "Divide"
);
// Remove the key 1 and its value
// from associative array
unset($arr['3']);
// Display the array elements
print_r($arr);
?>
2. Example:
Input:
Array(
"1" => "Soltuts",
"2" => "sol",
"3" => "Divide"
);
Output:
Array ( [1] => Soltuts [2] => sol )