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.
<?php
$a['id'] = 1;
$html .= '<a href="{$a['id']}">Link</a>';
?>
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.
<?php
$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>';