Ive got an if statment which im using in php as part of a foreach loop.
What id like to do is make the if statement a variable so that i could just call the variable. Somthing like this
$best_xml = if ($wh_odds_attrib['oddsDecimal'] < $lad_odds_attrib['oddsDecimal']) {
$lad_odds_attrib['oddsDecimal'];
}
else {
$wh_odds_attrib['oddsDecimal'];
};
But i keep getting this error when i run it – Parse error: syntax error, unexpected ‘if’ (T_IF) in /Applications/MAMP/htdocs/event.php on line 74 (line 74 is the first line starting $best_xml)
Is this possible / is this the right way to do it ?
ifstatements don’t evaluate to an assignable value in PHP. You can’t assign an if statement to a variable.You can, however, use the ternary operator: