|
Posted by Rik on 05/27/06 15:43
Rik G. wrote:
> OK, thanks, that looks better but still: why does it eat the strings
> "2 + 2 = " and "test " in case 1 and 3?
See my other post.
> And here's for something even but uglier:
>
> echo "2 + 2 = " . 2+3; // This will print 5
1. String "2 + 2 = ".
2. String "2 + 2 = 2".
3. Gets cast to an integer because of +, which results in the first number:
integer "2".
4. Integer 2 + Integer 3 = 5
> echo "2 + 2 = " , 2+3; // This will print 2 + 2 = 5
1. String "2 + 2 = " get's echoed seperately.
2. Calculation 2+3 is performed.
3. Integer 5 is echoed seperately (the , operator is way, way down the
precedence list).
> echo "test " . 2+3; // This will print 3
1. String "test ".
2. String "test 2".
3. String gets cast to an integer, the first character is not a number or
'-' followed by a number, so gets cast to integer 0.
4. 0+3 = 3
Grtz,
--
Rik Wasmus
[Back to original message]
|