+ 3
Why the result is 0 in the script below?
https://code.sololearn.com/wXhOF1ZxuxXV/?ref=app Strasse answer but fact.
7 ответов
+ 5
idk its kinda part of php where string that doesnt have recognizeable numeric at the start will result in 0 if casted.
since the operation is + i think php will treat the variable as number, so it'll cast that to number which is 0 for both of them. so 0 + 0 = 0.
the result will be different if you use $crbl="7 world";
+ 4
If you Wand to combine strings use
$combined=$first . $second
+ 4
OK, I expected - hello world.
Thanks, all of You, espacially to You, David.
+ 3
EGO What result were you expecting?
+ 3
every one but not 0 -:) BEFORE these posts.
+ 3
So, IF You write echo $crbl, it is appeared 'world' but not zero.
+ 3
EGO PHP uses the dot (.) operator to concatenate string values.
Therefore, the following line would result in "helloworld":
$vrbl . $crbl
However, the code is using the plus (+) operator, which will attempt an arithmetic addition on the 2 operands.
If the operand is a string with a value that cannot be converted into a number, it appears that PHP will use the default integer value, which is 0.
Therefore, "hello" + "world" is essentially the same as 0 + 0.