Connecting Tech Pros Worldwide Help | Site Map

I have seen much, but this...

  #1  
Old October 18th, 2006, 02:35 PM
jodleren
Guest
 
Posts: n/a
I have 2 pieces of code, where one works, another does not, even they
should be the same

echo " <td$s $s2</td><td>$s-";
echo $s+$s2." </td></tr>\r\n";

which can be truncated to

echo " <td$s $s2</td><td>$s-".$s+$s2." </td></tr>\r\n";

All in one line, but then the first part in the "" will not be printed,
result: 45</td></tr- a funny table.
There should be no difference, but there is.

$s and $s2 are integer, the entire table is for debugging. The error is
known and I can work around this.

But i cannot explain it.

BR
Sonnich

  #2  
Old October 18th, 2006, 02:55 PM
Moot
Guest
 
Posts: n/a

re: I have seen much, but this...


jodleren wrote:
Quote:
I have 2 pieces of code, where one works, another does not, even they
should be the same
>
echo " <td$s $s2</td><td>$s-";
echo $s+$s2." </td></tr>\r\n";
>
which can be truncated to
>
echo " <td$s $s2</td><td>$s-".$s+$s2." </td></tr>\r\n";
>
All in one line, but then the first part in the "" will not be printed,
result: 45</td></tr- a funny table.
There should be no difference, but there is.
>
$s and $s2 are integer, the entire table is for debugging. The error is
known and I can work around this.
>
But i cannot explain it.
>
BR
Sonnich

When doing math within a string concatenation, you need to use
parethesis.
So your second example becomes:
echo " <td$s $s2</td><td>$s-". ($s+$s2) ." </td></tr>\r\n";

  #3  
Old October 18th, 2006, 02:55 PM
p.lepin@ctncorp.com
Guest
 
Posts: n/a

re: I have seen much, but this...



jodleren wrote:
Quote:
echo " <td$s $s2</td><td>$s-";
echo $s+$s2." </td></tr>\r\n";
>
which can be truncated to
>
echo " <td$s $s2</td><td>$s-".$s+$s2." </td></tr>\r\n";
Precedence. Try:

echo " <td$s $s2</td><td>$s-".($s+$s2)." </td></tr>\r\n";
Quote:
There should be no difference, but there is.
Of course there *is* quite a difference. You just failed to
notice it.

--
Pavel Lepin

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why do I have to prefix stat from <sys/stat.h> with the keyword struct? Rolf =?UTF-8?B?S3LDvGdlcg==?= answers 2 March 12th, 2008 11:55 PM
Please help with this IE problem Alan Silver answers 9 July 25th, 2007 11:55 AM
dotnet controls seen much differently on IE and on netscape. - second post Mr. x answers 0 November 18th, 2005 01:14 AM
dotnet controls seen much differently on IE and on netscape. Mr. x answers 6 November 18th, 2005 01:13 AM