What is the potential cause of the error "Fatal error: Cannot use string offset as an array" in PHP?

The error "Fatal error: Cannot use string offset as an array" in PHP occurs when trying to access a string as an array. This typically happens when trying to treat a string as an array by using square brackets to access individual characters. To fix this issue, you need to ensure that you are working with arrays where necessary and strings where expected.

// Example of fixing the "Fatal error: Cannot use string offset as an array" error
$data = "Hello";
// Accessing individual characters in a string should be done using string functions
$firstChar = substr($data, 0, 1);
echo $firstChar; // Output: H