11-29-2008, 09:28 AM
|
#6 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
Quote:
Originally Posted by t3st
have it this way.
PHP Code:
<?php
echo "Testing " . (1 + 2) . "34";
?>
I think one of the reason why it will displays 234 is because php reads each line from right to left. And "34" is a string, and when we try to concatenate 2 to 34, 2 will be included as a string also. And bear in mind that we can't do operations like addition, subtraction, etc both strings and integers right?
Im not quite sure about it, but maybe its one of the reason.
|
I think you've gone far enough. I've detailed below how PHP does the calculations:
PHP Code:
echo "Testing " . 1 + 2 . "34";
step1: echo "Testing1" + 2 . "34"; step2: echo 0 + 2 . "34"; step3: echo 2 . "34"; step4: "234" (string!);
I think you've got it...hopefully. You might want to ask why have I wrote a 0 in there. Well, it's simple enough: any string has the integer value of 0. When doing math between a string and a number, the string always has the value 0.
That's why you need to put your calculations in paranthesis when doing calculations like that.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
Last edited by xenon : 11-30-2008 at 07:44 PM.
|
|
|
|