Reputation: 173
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.
Upvotes: 2
Views: 110
Reputation: 755
You need to use a ternary operator.
Example:
$html = 'blabla' . ($a == $b ? 'write something' : 'or something else');
Upvotes: 4
Reputation: 1423
You probably want to do something like this.
<?php
$html = 'Your order was ';
if ($order->status === 'success') { // I don't know just doing something random
$html .= ' successful';
} else {
$html .= ' unsuccessful';
}
Upvotes: 0
Reputation: 13728
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
Upvotes: 1