0

[PHP] Assignment Operator

Can anyone explain me what is wrong with the assignment operator ? For example i've encountered a challenge recently which was like this. $var = "hello"; $var += 6; echo $var; The answer was 6 But I really cannot get it. For what I've seen in internet, when there is += operator, it just makes like this. $x += 6 >>>>> $x = $x + 6 Then why the answer isin't 'hello 6' ???

21st Jun 2018, 5:12 PM
Antonio Parroni
Antonio Parroni - avatar
4 Respostas
+ 2
Antonio Parroni the challenge isnt weird. php is weird. the challenge teaches you the weirdness of php
21st Jun 2018, 5:34 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 1
php,php..php a language of utmost weirdness. the += operator is very unstable for string concatenation in php.. use "." $var="hello"; $var=$var."6"; echo $var;
21st Jun 2018, 5:29 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 1
Brains🇳🇬 haha, makes sense. Thanks
21st Jun 2018, 9:04 PM
Antonio Parroni
Antonio Parroni - avatar
0
Brains🇳🇬 then why such a weird challenge like this is present in the system ? This is just unfair 🤒
21st Jun 2018, 5:33 PM
Antonio Parroni
Antonio Parroni - avatar