How can I add if function in my PHP code below :
$html = 'blabla
'.if($a = $b).'
{
}
';
When I run that code, it show error like this :
Parse error: syntax error, unexpected 'if' (T_IF) in...
Please help to advice.
Thanks.
How can I add if function in my PHP code below :
$html = 'blabla
'.if($a = $b).'
{
}
';
When I run that code, it show error like this :
Parse error: syntax error, unexpected 'if' (T_IF) in...
Please help to advice.
Thanks.
You need to use a ternary operator.
Example:
$html = 'blabla' . ($a == $b ? 'write something' : 'or something else');
'blabla' . ($a == $b) is seen as the expression (not ($a == $b)), since . (string concatenation) has a higher precedence than ?: (ternary).use append again to string and use == to compare like
$html = 'blabla';
if($a == $b){
$html .='yes';
}
or use ternary operator like @Viktor Svensson answer