[PHP] Assignment Operator | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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
į Œį ŒBrains[Abidemi]
į Œį ŒBrains[Abidemi] - 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
į Œį ŒBrains[Abidemi]
į Œį ŒBrains[Abidemi] - 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