Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old October 18th, 2006, 02:35 PM
jodleren
Guest
 
Posts: n/a
Default I have seen much, but this...

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
Default 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
Default 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

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles