Jump to content
xisto Community
Sign in to follow this  
awesomebill61

Php Syntax Question

Recommended Posts

this is an error i have dealt with for a long time and it doesn't really make much sense to me.

if i am parsing a string, and try to put an array variable in it, it returns an error
example:

echo "This is a variable: $array['var']";
that will return an error.
I have tried to get around it by doing
$array[\'var\']
and
$array[\"var\"]
but those just return different errors. I can get rid of the error by using this:
$array[var]
but it says right in the php manual that that is a no-no

the only two ways i know to escape are to assign the value to a string variable or to concatenate.
$var = $array['var'];echo "This is a variable: $var"
echo "This is a variable: " . $array['var'];

the first is rather cumbersome with large arrays, and the second is kind of messy the way i see it.
does anyone know how to get around this?

Share this post


Link to post
Share on other sites

I dont know what it's called but I came across it somewhere.. cant remember that either lol. anywhere here it is and this is what i use


echo"<span class='header'>Title</span> {$rs['title']}";

if I don't use the {} around the array/resource, it won't work. hope that helps ya out and if anyone can shed some light on its former name and use of the {} in this case, it would be appreciated.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.