An interview question about PHP variable references

  • 2020-03-31 20:59:55
  • OfStack

PHP interview questions are as follows:
 
<?php 
$a = 1; 
$x =&$a; 
$b=$a++; 
?> 

Q:
What are the values of $b and $x?

The answers to the PHP interview questions are as follows:
$b = 1;
$x = 2;

See? I don't understand. Think again. When a variable is equal to a reference to another variable, either side changes its value, and the other side sees the value change. The first addition will show, and then the next addition will show.

Related articles: