Reply to Re: Butt ugly

Your name:

Reply:


Posted by Norman Peelman on 05/28/06 16:02

"Oli Filth" <catch@olifilth.co.uk> wrote in message
news:8f9eg.1527$xH1.1194@newsfe3-gui.ntli.net...
> Norman Peelman said the following on 28/05/2006 03:45:
> > "Chung Leong" <chernyshevsky@hotmail.com> wrote in message
> > news:1148755585.431248.282160@j55g2000cwa.googlegroups.com...
> >> Rik wrote:
> >>> Let's say $text = "2 + 2 = " or " = 2 + 2"
> >>>
> >>> echo 2 + 2 . $text;
> >>> echo $text . 2 + 2;
> >>>
> >>> It just makes sense to me....
> >> Well, it didn't make sense to the other Rik ;-)
> >>
> > It makes sense because as soon as you try to ADD a number to a
'string'
> > (or a 'string' to a 'string'), the strings are lost (counted as zero):
> >
> > echo 'A + B = ' . 'A' + 'B';
> >
> > will output zero (0)
> > 'A + B = ' . 0 + 0 = 0
> > 0 . 0 = 0
> > 0 = 0
>
> Actually, that's doing:
> 'A + B = ' . 'A' + 'B'
> 'A + B = A' + 'B'
> 0 + 0
> 0
>
> (the . is evaluated first, due to left associativity.)
>
>

You are correct, and that was my intention to show that basically the 'A' +
'B' (right side of = sign) evaluated to 0 at some point; 'B' = 0...

> > It's
> > not really about precidence at all as no math is done within quoted
strings
> > (literals).
>
> It's *all* about precedence (and associativity, indirectly), and that's
> the point Chung was making.
>
> The fact that the examples all contain things like "A + B = " is
> irrelevant, and just confusing things...
>
>

True!

The big problem I think is that Chung is comparing apples to oranges. The
'+' function causes non-number strings to be evaluated as zero (0) and the
'.' function causes type conversion. The solution is to pay attention to
what the desired result is and use the '( )' parentheses to force the proper
precedence. See my post to Chung...

Norm

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация