如何在双引号php字符串中插入php变量


How to insert php variable inside a double quoted php string

如何在html字符串中插入php变量?我试着这样做,但它跑不动了。请参阅下面的代码。

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

您错过了最后的'。此外,您需要使用PHP串联运算符.将它们连接起来,以将字符串与变量连接起来

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