Home > Backend Development > PHP Tutorial > 求解一个php数组的用法,该如何解决

求解一个php数组的用法,该如何解决

WBOY
Release: 2016-06-13 12:04:16
Original
879 people have browsed it

求解一个php数组的用法
看到一句别人写的代码,类似是这样的:

<br />$a = array();<br />$a['key'] = $a['key'] + 1;<br />var_dump($a);<br />
Copy after login

打出来后看,代码中的1变成了数组a的值。。
这个。。从来没这样用过。。
------解决方案--------------------
等价于 $a['key'] = null + 1; 
------解决方案--------------------
$a = array();
$a['key'] = $a['key'] + 1; // 这个时候 $a['key']是不存在的,用isset($a['key']) 返回false,所以 $a['key'] = null
$a['key'] + 1 相当于 null +1 因为php会自动将null转为0进行算术运算,所以就是0+1 ,最后$a['key'] = 1了

var_dump($a);

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