在 PHP 中,使用什麼引用賦值運算子來指派引用?
假設我們有如下值 −
$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
廣告