How can variables be used in PHP to dynamically access array elements?

To dynamically access array elements in PHP using variables, you can use the variable as the index within square brackets when accessing the array. This allows you to access array elements based on the value of a variable, making your code more flexible and dynamic.

$array = ['apple', 'banana', 'cherry'];
$index = 1;

echo $array[$index]; // Output: banana