I have an if statement that I want to control with having one field needing input and they have to pick one of the other 2 choices.
if(test1 && test || test3){
//Something here
}
Should I do it like this:
if(test1 && (test2 || test3)){
//do stuff
}
How would I go about doing this. I can’t wrap my head around the logic…
For the
/* Do something */bit of code to be executed, the if statement has to evaluate toTRUE.This means, that
$requiredFieldmust beTRUE, and so must be($optional1 || $optional2).For
$requiredFieldto beTRUE, it just needs to be filled in – and for the second part:($optional1 || $optional2)eitheroptional1oroptional2would do it.Edit:
After rereading the question, it seems that I might have misunderstood you. If the user must enter one specific piece of information, and must choose only one (not both) out of two options – then the following should be used.
This means that
$optional1or$optional2must be filled out – but not both of them.