<?php
$b="c";
$c=7;
$i=&$c+$$b;
var_dump($i);
?>
为什么我的输出是 int(7)?你能告诉我原因吗?我认为 $i 值是 7+7=14 但结果让我很模糊。
最佳答案
是因为引用。优先级 Reference + string = Reference。考虑一下。
$b = 7;
$a = &$b; // $a now points to $b;
$a = '?'; // The value where $a points is '?'
echo $b; // 7
现在 $a 是指针,是对 $b 的引用;你不能在上面添加字符串。
& 的优先级高于 +。
Check this for more detail
编辑
一个有趣的测试,可以更好地理解。
$a = 7;
$d = ($c = &$a + 1); // It is composite expression;
echo $c; // again 7 because & is given preference to +
echo $d; // 8 because that is the output of internal expression.
坦率地说,这对我来说很陌生。
关于php - PHP推理变量输出原理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41478377/