samedi 28 septembre 2019

truth tables in php with more then 3 variable

Hi StackOverflow people.

if i have 3 variable out side of the loop called :

 $atr
 $ber
 $cdr

Another system will provide 2 option value for this 3 variable: Empty or not empty.

and other 3 variables inside the loop: the value for each variable come from Another system and depend on $i every loop will get different value

$aa 
$bb 
$cc

now my code:

function SelectAll2()
{

$arrArraySize = 283;

$atr =  Empty or not empty.;
$ber =  Empty or not empty.; 
$cdr =  Empty or not empty.; 


if($atr=="" && $ber=="" && $cdr==""){ represent 0 0 0
  return 1;
}
elseif($atr=="" && $ber=="" && $cdr!=""){
  for ($i=1; $i<$arrArraySize; $i++)
  {
  $cc = value come from Another system and depend on $i every loop will get diffrent value
    if( $cdr==$cc){ 
    return 1;
    }
  }
}elseif($atr=="" && $ber!="" && $cdr==""){  represent 0 1 0
  for ($i=1; $i<$arrArraySize; $i++)
  {
  $bb = value come from Another system and depend on $i every loop will get diffrent value
    if($ber==$bb){ 
    return 1;
    }
  }  
}elseif($atr!="" && $ber=="" && $cdr==""){  represent 1 0 0
  for ($i=1; $i<$arrArraySize; $i++)
  {
  $aa = value come from Another system and depend on $i every loop will get diffrent value
    if($atr==$aa){ 
    return 1;
    }
  } 
}elseif($atr=="" && $ber!="" && $cdr!=""){   represent 0 1 1
  for ($i=1; $i<$arrArraySize; $i++)
  {
  $bb = value come from Another system and depend on $i every loop will get diffrent value
  $cc = value come from Another system and depend on $i every loop will get diffrent value
    if($ber==$bb && $cdr==$cc){ 
    return 1;
    }
  } 
}elseif($atr!="" && $ber=="" && $cdr!=""){   represent 1 0 1
  for ($i=1; $i<$arrArraySize; $i++)
  {
  $aa = value come from Another system and depend on $i every loop will get diffrent value
  $cc = value come from Another system and depend on $i every loop will get diffrent value
    if($atr==$aa && $cdr==$cc){ 
    return 1;
    }
  } 
}elseif($atr!="" && $ber!="" && $cdr==""){  represent 1 1 0
  for ($i=1; $i<$arrArraySize; $i++)
  {
  $aa = value come from Another system and depend on $i every loop will get diffrent value
  $bb = value come from Another system and depend on $i every loop will get diffrent value
    if($atr==$aa && $ber==$bb){ 
    return 1;
    }
  } 
}else{     represent 1 1 1
  for ($i=1; $i<$arrArraySize; $i++)
  { 
  $aa = value come from Another system and depend on $i every loop will get diffrent value
  $bb = value come from Another system and depend on $i every loop will get diffrent value
  $cc = value come from Another system and depend on $i every loop will get diffrent value
    if($cdr==$cc && $atr==$aa && $ber==$bb){
      return 1;
    } 
  }
}
}

there is a way to write this code more effectively?

because it's messy and it's for only 3 outside loop variable ($atr,$ber,$cdr) and 3 inside loop variable ($aa,$bb,$cc)

and i need this for 4 variable and even 6. if its 6, for example, I can add other 3 outside variable ($atr,$ber,$cdr,$fdsf,$tre,$dsds) and other 3 inside variable ($aa,$bb,$cc,$dd,&ee,$ff)

thanks!

Aucun commentaire:

Enregistrer un commentaire