一道关于变量引用的php面试题

php面试题题目如下:

<?php
$a = 1;
$x =&$a;
$b=$a++;
?>

问:
$b和$x的值分别是什么?

php面试题的答案如下:
$b = 1;
$x = 2;

明白了吗? 没明白,再好好想想。 当一个变量等于另一个变量的引用的时候,这时任何一方改变了其值,另一方看到的这个值也会变化的。前加本次就表现出来,而后加下一次才会表现出来。


Leave Your Comment

Your email will not be published or shared. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

*
请输入图片中的字符以验证你并非垃圾机器人. 点击图片收听验证码的语音版.
点击这里收听此验证码的语音版本