Solution to Cannotuseascalarvalueasanarray in php. When I was testing the php program today, I encountered an error: Cannotuseascalarvalueasanarray. the error message returned a few days ago. it seems like I have fine-tuned it. today, when I was testing the php program, the following error message is displayed: Cannot use a scalar value as an array. the error message is also displayed a few days ago. it seems that you have fine-tuned it and didn't go into details, today, it appears again.
I can't confuse myself any more. I have to find out the cause and solution, so I went online to search for it. I haven't found any results for a long time. it's not that I can't find such a problem on the Internet, but few people make positive and accurate answers. The last text in this article makes me suddenly understand what is going on.
--------------
Note the following type conversion:
If a variable name (such as a) has been defined as a non-array type, such as integer, a can be converted to floating point, string (or even object type), but cannot be an array, that is, a [0] = 1; is incorrect. php will report the warning "Cannot use a scalar value as an array". Even if a is defined as a one-dimensional array, it cannot be converted into a high-dimensional array.
--------------
The solutions to the problems found by other netizens are as follows:
After seeing this sentence, I carefully checked the code and found that a Boolean variable I have defined above was called directly as an array at the bottom, so an error occurred.
If you have defined a non-array element and assigned a value, and used it as an array, the Cannot use a scalar value as an array error will occur.
For example, var $ I = 1000;
$ I [5] = 345; // an error occurs at this time,
Therefore, we should give up this nonstandard code writing method.
Please use a scalar value as an array, this error prompt is also issued a few days ago, it seems like a little fine-tuned at that time just fine...