PHP双引号字符串问题

时间:2018-03-16 09:48:01

标签: php

我试图将变量的值放在行内:

$email .= "What do you need the container for?: $json['purpose']";

但是我收到了这个错误:

syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

如何解决此问题?

1 个答案:

答案 0 :(得分:5)

解决方案一(附上{}):

$email .= "What do you need the container for?: {$json['purpose']}";

解决方案二(逃脱):

$email .= "What do you need the container for?: ".$json['purpose']."";

他们都工作:)