claudios claudios - 7 months ago 20
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.

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

Answer

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