NYCPHP Meetup

NYPHP.org

[nycphp-talk] New to group and array question

csnyder chsnyder at gmail.com
Mon Sep 11 14:11:35 EDT 2006


On 9/10/06, Tim Lieberman <tim_lists at o2group.com> wrote:
> David,
>
>     In general, yes, use single quotes.  Using double-quotes will cause
> PHP to interpret the string, and is necessary if the key has a variable
> in it, for example: $myarray["something_$var"], with $var=='foo', will
> get you the value of $myarray['something_foo'].
>
>     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: ' .
> $user['last_login']';
>


For what its worth, you need to use a similar strategy when
referencing object properties that are more than one "level" deep.

"Hello $user->name." will work, but "Hello $auth->user->name." will not.


-- 
Chris Snyder
http://chxo.com/



More information about the talk mailing list