问题
I'm working on a tree structure in PHP. When looping through the nodes, an exception is sometime thrown because some node that should not be null is null, more precisely it's set to "&NULL":
array(13) {
// ...
// some data...
// ...
["segments"]=>
NULL
["leaf"]=>
bool(false)
["children"]=>
&NULL
}
Since it's not inside quotes, I assume it's some kind of special value, but what does it mean?
回答1:
It just means that it is a reference to a value NULL
$a = array();
$n = null;
$a[1] =& $n;
var_dump($a); // array(1) { [1]=> &NULL }
If you change $n = null; to $n = 1; - then you'll get &int(1)
回答2:
It's a reference to a value that is null. "&" is the reference symbol.
来源:https://stackoverflow.com/questions/10792325/what-does-a-variable-set-to-null-means-in-php