>> ... Mostly, so that I pick up the
>> preferred habit if nothing else.
[quoted text clipped - 14 lines]
> is better as:
> 1. echo 'error is ' . $error;
.oO(Twayne)
>OHHHHHhhh, now you've gone and done it! I told myself I'd not get into
>that one yet as it was going to make me look even stupider (is that a
[quoted text clipped - 8 lines]
>instance:
>echo "He drank some {$beer}s";
This would output "He drank some ", followed by the content of the
variable $beer, followed by a literal "s". But what about this:
$beer = 5;
echo "He drank some $beers";
Which variable would you want PHP to use - $beer or $beers? In fact PHP
would try to use $beers, which doesn't exist, so the code will throw a
notice.
> All the explanations note that 's' is a valid character for variable
>names, but ... so what? If $beers='beers', then, OH! ... Are these
>examples trying to say that one cannot make a var plural of, say,
>$beer='beer' by simply adding the "s" to it? Is THAT what it's
>trying to point out? Boy, if that's the case, they do a lousy job of
>it! <g>.
The {} inside a string just help to avoid ambiguities and allow more
complex expressions. See the examples in the manual.
http://www.php.net/manual/en/language.types.string.php#language.types.string.par
sing.complex
>I considered deleting the foregoing and rewording it, then decided
>against deleting it so you can see where my head is.
[quoted text clipped - 3 lines]
> then printing/echoing "beers" is {$beer}s, and NOT $beers ;
>correct?
No, as shown above. The parser sees $beers and tries to use that
variable. If you want it to use $beer instead, you have to use curly
braces.
>That seems suspicious to me because I can't see why anyone
>would try to do it the wrong way in that case. So though I'm not
[quoted text clipped - 7 lines]
> So if I'm wrong, then can you explain a differenct significance of
>the "s" in the examples?
It's not about the "s", it's about the variable names in general and how
the parser interprets the string:
$bar = 42;
print "foo $barr";
print "foo {$bar}r";
Two different things. The {} help to tell the parser exactly how you
want it to interpret the string.
>lol, if I haven't made a completely *clear's mud* post out of this, any
>clarification/verification would be most appreciated.
>Also, if you were just trying to confuse me with (['({fact}s'])), then
>_shame_ on you<g>! Yeah yeah, I know, all newbies have to pay their
>dues, but ... .
;)
HTH
Micha
Twayne - 04 Jul 2008 23:50 GMT
> .oO(Twayne)
>
>> OHHHHHhhh, now you've gone and done it! I told myself I'd not get
>> into that one yet as it was going to make me look even stupider (is
>> that a word?<g>) than I've already made myself look! :^)
...
> The {} inside a string just help to avoid ambiguities and allow more
> complex expressions. See the examples in the manual.
>
> http://www.php.net/manual/en/language.types.string.php#language.types.string.par
sing.complex
Excellent reference; many thanks. Duly bookmarked & saved.
...
> No, as shown above. The parser sees $beers and tries to use that
> variable. If you want it to use $beer instead, you have to use curly
> braces.
Great. I "know" (but didn't recall) that it'd look for what was
written, not necessarily what I "meant"<g>. First time I've hooked up
curly braces to it, so that's good lesson learned. Learning &
experiencing what one learned are two different things.
...
> It's not about the "s", it's about the variable names in general and
> how the parser interprets the string:
THANK YOU! I needed to hear that.
> $bar = 42;
> print "foo $barr";
> print "foo {$bar}r";
>
> Two different things. The {} help to tell the parser exactly how you
> want it to interpret the string.
As usual when I'm getting started with something new, I overthunk it!
So much for the "ThiMk" sign over my desk, too.
I have a decent handle on it now, and a couple other things too, based
on the link you provided. I always look for phpnet and w3school links
when I'm searching but I guess my search terms weren't close enough this
time.
Once more, thanks for your time & patience, & best regards,
Twayne
Michael Fesser - 04 Jul 2008 23:58 GMT
.oO(Twayne)
>[...]
>
>Once more, thanks for your time & patience, & best regards,
You're welcome.
Micha
Geoff Berrow - 05 Jul 2008 10:19 GMT
Message-ID: <LOxbk.275$9W.114@trndny04> from Twayne contained the
following:
>> It's not about the "s", it's about the variable names in general and
>> how the parser interprets the string:
>
>THANK YOU! I needed to hear that.
I just love a good ker-ching moment...

Signature
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
>>> Hi,
>>>
[quoted text clipped - 79 lines]
>
> Twayne
Just keep in mind that the curly braces isolate variables from the
rest of the string, and if not using concatenation '.' are required in
certain circumstances:
$array['car']['make']['color'] = 'silver';
echo "Joe drives a $array['car']['make']['color'] car."; //doesn't work
echo "Joe drives a $array[car][make][color] car."; //doesn't work
echo "Joe drives a {$array['car']['make']['color']} car."; //works
Points to remember:
Single quotes around array keys are not needed when the array variable
is embedded inside double quoted string. But they are required when
using curly braces to isolate the variable.
Single quotes around array key names are required inside curly braces.
Curly braces are required around multi-dimensional arrays.

Signature
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
Twayne - 06 Jul 2008 18:08 GMT
...
> Just keep in mind that the curly braces isolate variables from the
> rest of the string, and if not using concatenation '.' are required in
[quoted text clipped - 16 lines]
>
> Curly braces are required around multi-dimensional arrays.
Hmm, that's wording I can remember and good clarification that's worthy
of my lists too.
Thanks, Norman
Twayne