On 9 May 2002 at 15:25, Philip Hallstrom wrote:
> It has to do with precedence (I think). When inside a double quoted
> string PHP evalutes "$books[$val]" *first* and doesn't catch that
> there's more to it...
>
> You can do this:
>
> $html.= " Yaddda yadda " . $books[$val][display];
>
> And I think this (or something close to it):
>
> $html.= " Yaddda yadda {$books[$val][display]}";
Yes, I remember someone writing about "how good" it was to do that:
$html.= " Yaddda yadda " . $books[$val][display];
personally I hate it :) ... I use Template::Toolkit in Perl and I
never muck about with html anything in my Perl. Someone once showed a
template system in PHP but it required more than I was willing to try
to do on my virtual server (had to install some Pear stuff on my
local linux box and move it to my freebsd virtual server and hope :)
Anyhow, thanks for the clues .. here is what I'm finding now:
http://www.php.net/manual/fi/language.operators.string.php
On the above page someone mentions what you do as well:
> "your choice is {$array['user']['choice']}"
odd thought that he single quoted the key names. I would have thought
not since everything was in double quotes. Superflous? or necessary?
Odd, imho. He also talks about better to single quote keys than
double quote owing to bypassing the need to parse between the single
quotes.
He says:
> Generally programmers are better to use ' when ' is applicable to
> avoid parse overhead. For example, use $array['item'] rather than
> $array["item"]. Your script will be executed a bit faster.
I find leads here:
http://www.php.net/manual/en/language.types.string.php#language.types.
string.parsing
Where I see this example (in complex syntax section):
> // This is wrong for the same reason
> // as $foo[bar] is wrong outside a string.
> echo "This is wrong: {$arr[foo][3]}";
there is no wrong reason above that example.
Note the single quote for the literal. I myself prefer{} and I'll
single quote all literals contained therein.
And then this is a nice page which kind of goes over the problem.
I've got a dense head and don't fully understand it all.
http://www.zend.com/zend/tut/using-strings.php
Just following up with comments and links in case someone else gets
bothered by this (got me for about 15 minutes before I just did what
I did to get it to work)
Peter
-- http://www.readbrazil.com/
Answering Your Questions About Brazil
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php