manalnor Posted August 31, 2010 Share Posted August 31, 2010 Hello friends, if i've the following php code echo 'something'; and i want to add php code for example ( call name from db ) <?=$ama[name]?> how to write it : i've tried this but didn't worked echo 'something $ama[name] '; can somone please show me how to write varibles inside echo. thanks Link to comment https://forums.phpfreaks.com/topic/212185-php-code-inside-echo-here/ Share on other sites More sharing options...
Pikachu2000 Posted August 31, 2010 Share Posted August 31, 2010 Anything in single quotes is interpreted as a string literal. You need to use double quotes, or string concatenation to output the value of the variable. $variable = 'rest of the string'; echo "This is the $variable."; echo 'This is the ' . $variable; Link to comment https://forums.phpfreaks.com/topic/212185-php-code-inside-echo-here/#findComment-1105660 Share on other sites More sharing options...
KevinM1 Posted August 31, 2010 Share Posted August 31, 2010 Array variables work different than 'normal' variables within a double-quoted string. Normally, something like: echo "Some value: $value"; Works just fine. For array variables, you need to stick them in curly braces for it to work, like so: echo "Look, it's an array variable: {$array[$key]}"; In your case, name needs to be put in single-quotes ($ama['name']). Link to comment https://forums.phpfreaks.com/topic/212185-php-code-inside-echo-here/#findComment-1105661 Share on other sites More sharing options...
Pikachu2000 Posted August 31, 2010 Share Posted August 31, 2010 Array variables work different than 'normal' variables within a double-quoted string. Normally, something like: echo "Some value: $value"; Works just fine. For array variables, you need to stick them in curly braces for it to work, like so: echo "Look, it's an array variable: {$array[$key]}"; In your case, name needs to be put in single-quotes ($ama['name']). Oh, yeah. I seem to have missed that part . . . Link to comment https://forums.phpfreaks.com/topic/212185-php-code-inside-echo-here/#findComment-1105663 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.