What is the role of unset() function in PHP when working with arrays?

The unset() function in PHP is used to remove a specific element from an array. This can be useful when you no longer need a particular element in an array and want to free up memory by removing it. To use unset() with arrays, you simply pass the array variable followed by the key of the element you want to remove.

// Example of using unset() function with arrays
$fruits = array("apple", "banana", "orange");

// Remove "banana" from the array
unset($fruits[1]);

// Output the modified array
print_r($fruits);