if(condition 1){
var=changeVar(var);
changed=true;
}
if(condition 2){
var=changeVar2(var);
changed=true;
}
if(condition 3){
var=changeVar3(var);
changed=true;
}
I don't like how changed=true;
is repeated three times.
You could save the old var
, and compare it?
oldVar = var;
//your code here.
changed = (oldVar != var);
I had ==
in there at first, but wouldn't that give a wrong (or at least different) sollution then in the question?
<?php
if (condition 1) {
var=changeVar(var);
}
if (condition 2) {
var=changeVar2(var);
}
if (condition 3) {
var=changeVar3(var);
}
changed=(condition 1||condition 2||condition 3||changed); // set changed value only if condition 1, condition 2 or condition 3 is true, keep old value otherwise
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With