0

I want to to create a string in php, but within the creation of the string I want to do a small calculation, here is an example of what I am trying but does not work.

$eggs = 2;

$breakfast = 'I ate '. $eggs-1 . ' eggs for breakfast today!';

Using PHP like this gives me a unexpected T_CONSTANT_ENCAPSED_STRING error.

1 Answer 1

5

You need to add brackets:

$breakfast = 'I ate '. ($eggs-1) . ' eggs for breakfast today!';
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.