Solution to PHP warning Cannot use a scalar value as an array_PHP Tutorial

WBOY
Release: 2016-07-21 15:21:07
Original
993 people have browsed it

I saw some prompts like this in the php error log:

[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 source program , probably as follows:

Copy code The code is as follows:

$arr_hx = $mem->get(' hx');
if(!$arr_hx) {
$arr_hx['a'] = 'b';
$mem->set('hx',$arr_hx);
}

Basically understood, when $mem->get does not get a value, it returns false. At this time, $arr_hx is false, a Boolean value, and then it is used as an array, resulting in This prompt was 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.

After checking, there is the following description:
Quotation
What needs to be noted is the type conversion:
If a variable name (such as a) has been defined as a non-array type, for example integer, then a can be converted to floating point, string (even object type), but it cannot be an array, that is, a[0]=1; is wrong, and PHP will issue 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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324941.htmlTechArticleI saw some prompts like this in the php error log: [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]...
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