What is the correct syntax for removing an element with a specific index from an array in PHP?

To remove an element with a specific index from an array in PHP, you can use the unset() function. This function will remove the element at the specified index and re-index the remaining elements in the array.

// Example code to remove an element with a specific index from an array
$index = 2; // Index of the element to be removed
$array = [1, 2, 3, 4, 5]; // Original array

unset($array[$index]); // Remove element at index 2

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