When you see the error message
syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
, this prompt indicates a problem with variable usage.
What happened to me was that an array was used in the statement, causing it to fail. Let’s look at the failed code below;
echo "I am an array, $n['x']";
?>
In this way, the instant double quotes can parse the variables , but the writing method of element group cannot be parsed. Just modify it to the following!
echo "I am an array, {$n['x']}";
?>
Adding curly braces {} allows the statement to identify that it is dynamic of.