在数组中的字符串中放入一个var


put a var within string within array

我有一个数组,我有这个:

$title = "Envirometal Recycling : Scrap Metal Recyclers Caboolture - Scrap products Zinc";

我想这样做:

$title = "Envirometal Recycling : Scrap Metal Recyclers <?php echo $suburb[$rand_keys[0]] . "'n";?> - Scrap products Zinc";

显然,上面的内容是错误的,我不确定我应该如何连接我的代码(不确定这是否是正确的措辞。

Concatenate是正确的单词:)

要在PHP中进行连接,请使用句点(.)。

 $title = "Envirometal Recycling : Scrap Metal Recyclers".$suburb[$rand_keys[0]]. "'n- Scrap products Zinc";

您也可以使用花括号,如:

$title = "Envirometal Recycling : Scrap Metal Recyclers {$suburb[$rand_keys[0]]}'n - Scrap products Zinc";

这样就不必出现围绕引号和双引号的奇怪串联情况。

$string = "John said, '" . $verbiage . "'";

我认为它看起来很干净,因为$string = "John said, '{$verbiage}'";

也许这就是你需要的?难以理解的问题

$title = "Envirometal Recycling : Scrap Metal Recyclers ". $suburb[$rand_keys[0]] . "- Scrap products Zinc";

然后回应整个

echo($title);
$title = "Envirometal Recycling : Scrap Metal Recyclers" . $suburb[$rand_keys[0]] . "- Scrap products Zinc";

应该做的技巧