How can the error "Fatal error: Cannot use string offset as an array" be prevented when working with arrays in PHP?

The error "Fatal error: Cannot use string offset as an array" occurs when trying to access an array element using a string as an index. To prevent this error, always make sure that you are using integers as indexes when working with arrays in PHP.

// Correct way to access array elements using integers as indexes
$array = [1, 2, 3];
echo $array[0]; // Output: 1