[nycphp-talk] New to group and array question
Tim Lieberman
tim_lists at o2group.com
Sun Sep 10 20:57:45 EDT 2006
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']';
David Krings wrote:
>Hello,
>
> my name is David and I am new in this group. I do some PHP for fun for my
>private web site and well, not to bore you with more details about me, here
>is my question. I always stumble across an odd thing with arrays. I read in
>many documentations and books that one should use the single quotes when
>referencing to an array element, such as $array['element']. Generally, this
>works fine and I use it that way, but it always fails when using it in echo
>or header statements (and probably a few others). The error I receive is
>parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or
>T_VARIABLE or T_NUM_STRING.
>
>I know how to get around this parse error by omitting the single quotes
>($array[element] instead of $array['element']), but I somehow am under the
>impression as if this isn't really the way to do it. I could assign it to a
>variable each time, but that is quite annoying (but maybe the right thing
>to do?).
>
>What is the significance of the single quotes? What is the expert advice on
>using or not using them? How would I package the single quote in an echo or
>header statement?
>
>
> Any enlightenment is greatly appreciated.
>
>
> David
>
>_______________________________________________
>New York PHP Community Talk Mailing List
>http://lists.nyphp.org/mailman/listinfo/talk
>
>NYPHPCon 2006 Presentations Online
>http://www.nyphpcon.com
>
>Show Your Participation in New York PHP
>http://www.nyphp.org/show_participation.php
>
>
>
More information about the talk
mailing list