Let’s say we have the following value −
$nextValue=100;
Let us take a new variable and assign a reference −
$currentValue = &$nextValue;
To assign a reference, use the reference assignment operator i.e. =&$anyVariableName in PHP.
The PHP code is as follows −
Example
<!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>
Output
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