What are the potential pitfalls of using unset() in PHP when removing elements from an array?
Using unset() to remove elements from an array can lead to unexpected behavior such as reindexing the array and potentially causing unintended side effects. To avoid these pitfalls, it's recommended to use array_splice() instead, which removes elements without changing the array keys.
$array = [1, 2, 3, 4, 5];
$keyToRemove = 2;
array_splice($array, $keyToRemove, 1);
print_r($array);