Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logic programming help

Tags:

php

logic

A = if infos !empty and inputs empty - do remove;

B = if infos empty and inputs !empty - do add;

C = if infos !empty and inputs !equal to infos - do add;

We can have like:

if B //it's the most common operation, so at the beginning.
{
  //add 
}
else
{
 //remove
}
elseif(c) 
{
 //the same add
} 

I believe this can be better thinking. Can I have your help?

Thanks in advance,

like image 377
MEM Avatar asked Sep 01 '26 11:09

MEM


2 Answers

if (B || C) 
{
  //add 
}
else
{
 //remove
}
like image 54
Dezigo Avatar answered Sep 04 '26 01:09

Dezigo


if (infos != inputs) {
    if (empty(inputs)) {
        // remove
    } else {
        // add
    }
}

Remember, the outermost condition checks that both values are never empty (never the same, actually). E.g.,

A = if infos !empty and inputs empty - do remove;

If inputs is empty infos can not be empty. Therefore, remove.

B = if infos empty and inputs !empty - do add;
C = if infos !empty and inputs !equal to infos - do add;

Different and inputs not empty => it doesn't mather whether info is empty => add.

like image 25
jensgram Avatar answered Sep 04 '26 01:09

jensgram



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!