将var放在数组中的字符串中

时间:2012-03-26 22:45:13

标签: php

我有一个阵列,我有这个:

$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";

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

4 个答案:

答案 0 :(得分:3)

Concatenate是正确的词:)

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

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

答案 1 :(得分:1)

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

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

然后回应整个事情

echo($title);

答案 2 :(得分:1)

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

应该做的伎俩

答案 3 :(得分:1)

你也可以像这样使用大括号:

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

然后你不必有奇怪的连接情况围绕引号和双引号。

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

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