0

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?

5
  • Try enclosing the variable with {} - like - {$json['purpose']} Commented Mar 16, 2018 at 9:49
  • You need to show more since it is using $json in it Commented Mar 16, 2018 at 9:49
  • show us the value of var_dump($json['purpose']); Commented Mar 16, 2018 at 9:51
  • Thanks {} worked. Commented Mar 16, 2018 at 9:53
  • More Learn at php.net/manual/en/… Commented Mar 16, 2018 at 9:53

1 Answer 1

5

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 :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.