+ 2
Explain this code ! (PHP)
<?php $a = "hello"; $a += ""; $a += "world"; echo $a; ?> Why the output is 0 ?
3 Answers
+ 5
Like KrOW said, you need to use the dot operator for string concatenation in PHP.
PHP is loosely typed, meaning it won't moan if you do crazy things with different types. The plus operator implies numerical addition, so that's what it will do! "hello" is equal to zero, but "5" would be equal to 5.
All your strings are numerically equal to zero, according to PHP!
+ 3
i know few of php but if my memory is good string concatenation is maded with dot "." operator
$a = $a." world";
and php dont show error if debug is disabled
+ 1
Use ". =" in PHP
not "+="
Concatenation in PHP work with "."(dot) symbol