Today, in testing the PHP program, there was a mistake: cannot use a scalar value as a array, this error prompted a few days ago, it seems to be a little tune on the good, also did not delve into, today but again appeared.
Can not be fooled, have to find out the reasons and solutions, so I went to search the Internet, ah, looking for a long time did not find the results, not on the internet is not found such a problem, but very few people do a positive and accurate answer. At last the passage of this article made me understand what was going on.
—————————————-
What you need to be aware of is type conversions:
If a variable name (such as a) has been defined as a non-array type, such as Integer, then a can be converted to floating point, string (or even object type), but not an array, that is, a[0]=1; it is wrong, PHP will quote such a warning " Cannot use a scalar value as a array ". Even if a is defined as a one-dimensional array, it cannot be converted to a high-dimensional array.
—————————————-
The following are the solutions to the problems found by other netizens: After seeing this, I examined the code and found that one of the Boolean variables I had defined above was called by me directly as an array, so there was an error.
If a non-array element is defined and assigned, and then used as an array, the error of cannot use a scalar value as a array appears.
such as: var $i = 1000;
$i [5]=345; There will be errors at this time,
So you have to give up this nonstandard way of writing code.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.