开发者

PHP Calculations inside string creation

开发者 https://www.devze.com 2023-01-07 15:29 出处:网络
I want to to create a string开发者_Go百科 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.

I want to to create a string开发者_Go百科 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.


You need to add brackets:

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

精彩评论

暂无评论...
验证码 换一张
取 消