How can elements be removed from an array in PHP?

To remove elements from an array in PHP, you can use the unset() function to unset specific elements by their keys or use array_splice() to remove elements based on their index positions.

// Example using unset() to remove elements by keys
$array = [1, 2, 3, 4, 5];
unset($array[2]); // Removes element at index 2
print_r($array); // Output: Array ( [0] => 1 [1] => 2 [3] => 4 [4] => 5 )

// Example using array_splice() to remove elements by index positions
$array = [1, 2, 3, 4, 5];
array_splice($array, 2, 1); // Removes 1 element starting from index 2
print_r($array); // Output: Array ( [0] => 1 [1] => 2 [3] => 4 [4] => 5 )