How can you remove an entry from an array in PHP and ensure that the array size shrinks accordingly?

To remove an entry from an array in PHP and ensure that the array size shrinks accordingly, you can use the unset() function to remove the specific element from the array. This function will remove the element at the specified index and shift all subsequent elements to fill the gap. This will effectively reduce the size of the array by one.

$array = [1, 2, 3, 4, 5];
unset($array[2]); // Removes the element at index 2 (value 3)
$array = array_values($array); // Re-index the array to ensure continuous keys
print_r($array); // Output the updated array