Solution to Cannot use a scalar value as an array under executescalar php

WBOY
Release: 2016-07-29 08:43:29
Original
1067 people have browsed it

Today when I was testing a php program, an error message appeared: Cannot use a scalar value as an array. This error message also appeared a few days ago. At that time, it seemed that it would be fine if I adjusted it a little. I didn't go into it deeply, but today it happened again. Appeared.
I can’t fool around anymore, I have to find out the reasons and solutions, so I searched and searched online, but I couldn’t find the result after searching for a long time. It’s not that such problems can’t be found online, but that very few people do it head-on and accurately. answer. The last paragraph of this article made me suddenly understand what was going on.
——————————————-
What needs to be noted is the type conversion:
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 (even object type), but not an array, that is, a[0]=1; is wrong, 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.
——————————————-
The following is the solution to the problem found by other netizens:
After seeing this sentence, I checked the code carefully and found that I had defined it above A Boolean variable was called directly as an array below, so an error occurred.
If a non-array element has been defined and assigned a value, and then used as an array, a Cannot use a scalar value as an array error will occur. For example: var $i=1000;
$i[5]=345; // An error will occur at this time,
So everyone should give up this irregular way of writing code.
The above introduces the solution to Cannot use a scalar value as an array under executescalar PHP, including the content of executescalar. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!