PHP 中引用赋值运算符如何赋值给引用?
phpserver side programmingprogramming更新于 2025/8/18 4:52:17
假设我们有以下值 −
$nextValue=100;
我们取一个新变量并赋值给引用 −
$currentValue = &$nextValue;
要赋值引用,请使用引用赋值运算符,即 PHP 中的 =&$anyVariableName。
PHP 代码如下 −
示例
<!DOCTYPE html> <html> <body> <?php $nextValue=100; $currentValue = &$nextValue; echo "Next Value=",$nextValue,"<br>"; echo "Current Value=",$currentValue,"<br>"; $nextValue = 45000; echo "After changing the value of next will reflect the current value because of =&","<br>"; echo "Next Value=",$nextValue,"<br>"; echo "Current Value=",$currentValue; ?> </body> </html>
输出
Next Value=100 Current Value=100 After changing the value of next will reflect the current value because of => Next Value=45000 Current Value=45000

