PHP warning Cannotuseascalarvalueasanarray solution

Source: Internet
Author: User
Tags php error log
PHP warning Cannotuseascalarvalueasanarray solution. For more information, see. The php error log contains the following prompts:

[27-Aug-2011 22:26:12] PHP Warning: Cannot use a scalar value as an array in/www/hx/enjoy. php on line 14
[27-Aug-2011 22:26:18] PHP Warning: Cannot use a scalar value as an array in/www/hx/enjoy. php on line 14

Check the source program, which is probably like the following:

The code is as follows:


$ Arr_hx = $ mem-> get ('hx ');
If (! $ Arr_hx ){
$ Arr_hx ['A'] = 'B ';
$ Mem-> set ('hx ', $ arr_hx );
}


Basically, when $ mem-> get does not get a value, the returned value is false. $ arr_hx is false, a Boolean value, and then it is used as an array, this prompt is generated. In fact, it is also a case where the variable is not defined. Add $ arr_hx = array () before the assignment to solve the problem.

Check the following description:
Reference
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.

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.