0

How this code works?

<?php $a = '1'; $b = &$a; $b = "2$b"; echo "$a , $b"; ?> Its printing 21 , 21. How?

18th Aug 2016, 11:30 PM
Bekir Uzun
Bekir Uzun - avatar
4 Respostas
+ 3
& - is passing by reference. So, in this case variable $b contain address of $a, but not it's value. When you are change value of $b - really you change value of $a.
19th Aug 2016, 7:04 AM
Наглый Лис
Наглый Лис - avatar
+ 3
its 10 add 7 and 3
6th Feb 2020, 5:13 PM
Alyssa Kay
Alyssa Kay - avatar
+ 1
Oh I get it. So $b is actually copy of $a because it points same address. Thanks.
19th Aug 2016, 9:17 AM
Bekir Uzun
Bekir Uzun - avatar
0
on row 3 "2$b" you just concatenate/merge the two values. at the moment $b = 1 -> 21
17th Nov 2017, 5:23 PM
assy