为什么不能用三元运算符选择引用?
Why reference can't be chosen with ternary operator?
这段代码:
$a = $condition ? &$x : &$y;
产生错误:
PHP Parse error: syntax error, unexpected '&' in php shell code
为什么 PHP 不允许在三元运算符中按条件选择引用?
试试这个
$a = &${($condition)?'x':'y'};
这段代码:
$a = $condition ? &$x : &$y;
产生错误:
PHP Parse error: syntax error, unexpected '&' in php shell code
为什么 PHP 不允许在三元运算符中按条件选择引用?
试试这个
$a = &${($condition)?'x':'y'};