JREAM Posted September 16, 2008 Share Posted September 16, 2008 Im getting tired of conconcenating(sp) Isnt there a way to do something like this: (I read it in my book in the past I think) print 'my name is {$name} and I like to {$hobby}'; print "my name is {$name} and I like to {$hobby}"; Is there a different rule with single versus double quotes? What am i doing wrong ? Quote Link to comment https://forums.phpfreaks.com/topic/124451-how-do-you-echo-variable-in-the-brackets/ Share on other sites More sharing options...
JasonLewis Posted September 16, 2008 Share Posted September 16, 2008 Single quote's do not parse variables inside them, you would need to break out of the string to echo out the variables. Quote Link to comment https://forums.phpfreaks.com/topic/124451-how-do-you-echo-variable-in-the-brackets/#findComment-642673 Share on other sites More sharing options...
matthewhaworth Posted September 16, 2008 Share Posted September 16, 2008 Use double quotes. echo "My name is $myName"; Quote Link to comment https://forums.phpfreaks.com/topic/124451-how-do-you-echo-variable-in-the-brackets/#findComment-642679 Share on other sites More sharing options...
JasonLewis Posted September 16, 2008 Share Posted September 16, 2008 Then if you want to use an array in the string you can use the curly brackets. $array = array("key" => "awesome"); echo "This is {$array['key']}!"; //Will output: This is awesome! Quote Link to comment https://forums.phpfreaks.com/topic/124451-how-do-you-echo-variable-in-the-brackets/#findComment-642685 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.