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