claudios claudios - 5 months ago 8x
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>';


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>';