Today, when testing the PHP program, there is an error message: Cannot use a scalar value as an array, this error prompted a few days ago, it seems like a little tune a bit better, did not delve into, today but appeared again.
Can not fool, to find out the cause and solution, so I went to search on the Internet Ah, find a long time have not found the results, not on-line search this problem, but very few people do a positive and accurate answer. The last piece of text in this article made me understand what was going on all of a sudden.
—————————————-
It is important to note the conversion of the type:
If a variable name (such as a) has been defined as a non-array type, such as an integer, then a can be converted to floating point, string (or even object type), but not an array, or a[0]=1, which is wrong, and PHP will report such a warning " Cannot use a scalar value as an array ". Even if a is defined as a one-dimensional array, it cannot be converted to a high-dimensional array.
—————————————-
Here are the solutions to the problems found by other netizens:
After seeing this sentence, I examined the code carefully and found that a Boolean variable I had defined above was called by me directly as an array, so there was an error.
If you have defined a non-array element and assigned a value, then use it as an array, and it will appear the error of cannot using a scalar value as an array
such as: var $i = 1000;
$i [5]=345; This error occurs,
So we have to give up this non-standard way of writing code.
The above describes the ExecuteScalar PHP on the cannot use a scalar value as an array solution, including the executescalar aspect of the content, I hope that the PHP tutorial interested in a friend helpful.