ExecuteScalar PHP solutions for cannot use a scalar value as an array

Source: Internet
Author: User
Tags scalar
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.

  • Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.