[nycphp-talk] New to group and array question

inforequest 1j0lkq002 at
Mon Sep 11 00:37:28 EDT 2006

Tim Lieberman |nyphp dev/internal group use| 

>    While I'm not entirely sure about how you're echoing stuff, try just
>not putting the array reference inside the string.  Instead, use the
>concatenation operator ".":
>    echo 'You are ' . $user['username'] . '.  Last login: ' .
Disclaimer: I am no where near the level of the prior responders when it 
comes to PHP skillz

I think this is very good advice, David. If there is one thing I learned 
about PHP, it is that PHP either makes rational sense or does not ;-) In 
other words, there is not much actual need to follow "dogma" if you 
understand how it works, except in those cases where PHP is kinda broke. 
The hard part is knowing when it is broke, and this list is a *great* 
resource for that. (please note I do suggest you follow best practices, 
because you can't recognize what is and isn't "dogma" unless you already 
know where all the real problems are).

To demonstrate, look at your responses here. Chris shows you how to 
embed the array element value into a string using curly braces (the 
actual way to do that, if that is what you really want to do). He also 
shows you (as do others) that concatenation is likely the key to your 
string building desires. Coming from other languages, you may not "think 
like that" but in PHP, that is a very good way to think. The concat 
operator (.) is your friend and works rationally. Also note how Chris 
defines precisely the use of single and double quotes... they, too are 
rational and do what they are supposed to do.

Finally, back to the first comment from Tim above. Tim wisely 
immediately  alluded to the idea that the way you are "echoing" your 
stuff may need attention. BINGO. "echo" in some ways is "broken", and is 
at least partly responsible for the confusion surrounding single and 
double quotes in strings built from hard coded characters and data 
values, especially when the data is embedded into arrays, and especially 
when the coder attempts to extract those values directly into strings 
"built" to be displayed to the browser. We have come full circle... you 
could go to curly braces, work out the rational details of the proper 
single quoted array "keys", and/or recognize that the encompassing 
"echo" command is imposing some restrictions on the way your content can 
be described and look at alternative ways to get your built data out to 
the browser.

I hope that's more helpful than it looks. You have all you need to 
advance in those early responses.

-=john andrews

"If you think this stuff is confusing, you should try optimizing websites for search engine exposure."  john andrews SEO

More information about the talk mailing list