简体   繁体   中英

PHP double quote string issue

I am trying to put my variable's value inside the line:

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

However I get this error:

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

How do I fix this issue?

Solution one (Enclosing with {}):

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

Solution two (escape):

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

Both of them work :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM