How does the '&' symbol in PHP affect the outcome?

后端 未结 3 450
无人共我
无人共我 2021-01-03 08:32

I\'ve written and played around with alot of PHP function and variables where the original author has written the original code and I\'ve had to continue on developing the p

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-03 09:14

    Now if we add &

    $a = "hello";   # $a points to a slot in memory that stores "hello"
    $b = &$a;   # $b points to the same address in memory as $a
    
    $a = "world";
    
    # prints "world" because it points to the same address in memory as $a.
    # Basically it's 2 different variables pointing to the same address in memory
    echo $b;        
    ?>
    

提交回复
热议问题