Jump to content

Recommended Posts

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

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;

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']).

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 . . .  :-[

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.