Jump to content

will someone verify this logic please?


ahs10

Recommended Posts

i am updating some code and would like to know the logic behind my new code is correct.  here's my old code....

 

if (($data->sheets[0]['numCols'] > 9) ||

($data->sheets[0]['cells'][1][1] != "ID") ||

($data->sheets[0]['cells'][1][2] != "Date Submitted") ||

($data->sheets[0]['cells'][1][3] != "Group") ||

($data->sheets[0]['cells'][1][4] != "Comments")) {

    //do this

}

 

now i want to introduce a condition to those conditions, that depends on $userType.  it introduces $colCount to the logic, which i know will work fine, but i'm questioning the last line before the first curly brace....

 

if (($data->sheets[0]['numCols'] > $colCount) ||

($data->sheets[0]['cells'][1][1] != "ID") ||

($data->sheets[0]['cells'][1][2] != "Date Submitted") ||

($data->sheets[0]['cells'][1][3] != "Group") ||

($data->sheets[0]['cells'][1][4] != "Comments")) ||

(($data->sheets[0]['cells'][1][5] == "RVL") && ($userType == "Buda")) {

    //do this

}

 

i only want it to look for the RVL cell if the $userType is Buda.  i always want it to check the original conditions though, regardless.  is this correct?

Link to comment
https://forums.phpfreaks.com/topic/91306-will-someone-verify-this-logic-please/
Share on other sites

I would think it would be like this

    if (
      ($data->sheets[0]['numCols'] > $colCount ||
      $data->sheets[0]['cells'][1][1] != "ID" ||
      $data->sheets[0]['cells'][1][2] != "Date Submitted" ||
      $data->sheets[0]['cells'][1][3] != "Group" ||
      $data->sheets[0]['cells'][1][4] != "Comments")
      &&
      ($data->sheets[0]['cells'][1][5] == "RVL" && $userType == "Buda")
      )
    {
     //do this
}

 

Ray

that's exactly where i got confused..... i should have stayed in school long enough to take at least one logic class... uggg.

 

so basically i have two condition sets, one that always needs to be checked and one that only needs to be checked if userType == Buda.

 

so you're saying that i need to say (condition set 1-always) && (condition set 2-sometimes), rather than (condition set 1-always) || (condition set 2-sometimes)?

 

now that i think about it, are you sure?  why would it be AND, not OR?

 

if cond1 AND cond2 == true.... but what if cond2 is false, i still want cond1 to execute if it's true... so it would be OR.

 

sorry, i'm thinking in my post.  thanks for sparking this thought, but i think my original was correct.  thanks again!

You are right my bad. I read what you wanted wrong

 

you may have to check the buda first

    if ($userType == "Buda"){
      if(
      $data->sheets[0]['numCols'] > $colCount ||
      $data->sheets[0]['cells'][1][1] != "ID" ||
      $data->sheets[0]['cells'][1][2] != "Date Submitted" ||
      $data->sheets[0]['cells'][1][3] != "Group" ||
      $data->sheets[0]['cells'][1][4] != "Comments" ||
      $data->sheets[0]['cells'][1][5] == "RVL"){
      // do this

      }
    } else {
      if(
      $data->sheets[0]['numCols'] > $colCount ||
      $data->sheets[0]['cells'][1][1] != "ID" ||
      $data->sheets[0]['cells'][1][2] != "Date Submitted" ||
      $data->sheets[0]['cells'][1][3] != "Group" ||
      $data->sheets[0]['cells'][1][4] != "Comments"){
      // do this

      }
    }

 

Ray

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.