How can using $array[index] without quotes lead to unexpected behavior in PHP?

Using $array[index] without quotes in PHP can lead to unexpected behavior because PHP will treat index as a constant if it is not defined. This can result in PHP looking for a constant with that name instead of accessing the element at that index in the array. To solve this issue, always use quotes around the index when accessing array elements to ensure PHP interprets it as a string key.

$array = ["apple", "banana", "orange"];
$index = 1;

// Incorrect way (may lead to unexpected behavior)
// $fruit = $array[index];

// Correct way
$fruit = $array[$index];

echo $fruit; // Output: banana