PHP, better to set the variable before if or use if/else?
- by DssTrainer
So a simple one that I just never could find a straight answer on.
What is better (performance or otherwise):
$var = false;
If ($a == $b) {
$var = true;
}
or
If ($a == $b) {
$var = true;
} else {
$var = false;
}
I've heard arguments for both ways. I find the first cleaner to ensure I have it set, and a little less code too. The pro being that you may only need to set it once without conditional. But the con being that if the argument is true, it gets set twice.
I am assuming the second way is probably best practice