I know this is basic boolean logic, but I’m stuck:
I am looping through database results, and for each one I need to check for the following condition:
if($old_value != $new_value)
If the above is true, the action is:
$old_value = $new_value;
But there is a secondary condition. If the row is of type “date”, I need to also check that $new_value is not empty, but the action is still the same. Right now, I am doing it like this:
if($old_value != $new_value) {
if($type != date) {
$old_value = $new_value;
} elseif(!empty($new_value)) {
$old_value = $new_value;
}
I’ve oversimplified the above, but really that one-line action is actually several lines that I know I don’t need to repeat based on the secondary condition.
But I’m at a loss on what the right way to combine the inner condition with the outer condition. If I do something like:
if(($old_value != $new_value) && ($type == 'date' && !empty($new_value))
Then the only time it would return true is when the row is of type date.
Try:
That should do it. Let me know if you need help understanding why.