After upgrading php7, PHP program prompts an error: operator not supported for strings in causes and Solutions

PHP Fatal error: [] operator not supported for strings in…
 
After searching the information, I found that it was caused by the following reasons
 
When a variable is assigned a second time in the same page, but the inconsistent type of the value causes this error, the variable type can be declared again before the second assignment.
Simply put, it is the result of different types of assignments to the same variable on the same page.
 
Such as:
$a = “ABC”;
$a [] = “def”;
 
The solution
 
To check if your code has the way it was written in the above example, declare a variable once before each assignment or destroy it with the unset() function
 
Ex. :
$a = “ABC”;
unset($a);
$a [] = “def”;

Read More: