claudios claudios - 2 years ago 95
PHP Question

How to insert php variable inside a double quoted php string

How can I insert a php variable inside my html string? I tried to do it like this, but it won't run. Please refer to the code below.

$a['id'] = 1;
$html .= '<a href="{$a['id']}">Link</a>';

Answer Source

You missed out the closing '. Also, you need to concat them using the PHP concatenation operator . to join the string with the variable:

$a['id'] = 1;
$html .= '<a href="' . $a['id'] . '">Link</a>';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download