I am new to php. And string concatenation is difficult for me. I want to concatenate the following string:
$branch = 'apple'; $rules = "(product=='iphone')andManufacturer==".$branch; // result "(product == 'iphone')andManufacturer ==apple"
But the string I want:
"(product=='iphone')andManufacturer=='apple'"
Thanks.
Advertisement
Answer
Try this(Added single quote to the string):
$branch = 'apple'; $rules = "(product=='iphone')andManufacturer=='".$branch."'"; echo $rules;
Another solution(Wrap the single quotes in double quotes to branch variable):
$branch = "'apple'"; $rules = "(product=='iphone')andManufacturer==".$branch; echo $rules;
OUTPUT:
(product=='iphone')andManufacturer=='apple'