0

What I'm trying to achieve is a nested condition like if ((a = true && b = true) or (c = true && d = true)) {...}. This doesn't seem to be working for me.

To further explain: I have two variables in what we could call a 'top', and two variables in what we could call a 'bottom'. What I need to do is execute code if variables are true in both 'top' and 'bottom'.

To more succinctly illustrate:

if ((t1 = true && b1 = true) or
    (t1 = true && b2 = true) or
    (t2 = true && b1 = true) or
    (t2 = true && b2 = true)
) {
    ...do some stuff...
}

I'm tempted to call it 'conditional statement for lattice problem'... except it isn't really a lattice problem... but it does sort of look like a lattice if you drew it |X| ... s'yeah, you're amazing if you can tell me a good way to do this, and you're super amazing if you can tell me what I ought to call it.

3 Answers 3

3

= is used for assignment, == is used to test for equality, === is used to test for equality and equal types. You need to use either == or ===, depending on whether t1, t2, b1, b2 are already boolean or something else. Also the stuff that Adam said, except that or is perfectly valid.

Sign up to request clarification or add additional context in comments.

1 Comment

Well I feel a bit silly; tried checking them as != false earlier but didn't take it all the way through the function. Thank you much for the clearing up, Dan.
2

You need to use two equal signs == instead of =. Also, your variables need to have $ in front of them. And your "or" should be ||.

The logic is ok.

It should look like this:

if (($t1 == true && $b1 == true) ||
    ($t1 == true && $b2 == true) ||
    ($t2 == true && $b1 == true) ||
    ($t2 == true && $b2 == true)
) {
    ...do some stuff...
}

3 Comments

Technically, he can use or, but I agree, it would be ridiculous to do so.
I did not know that. Learn something new everyday :). php.net/manual/en/language.operators.logical.php
It's pretty inconsistent with PHP's C-like syntax.
0

change condition

if (($t1 == true && $b1 == true) or
($t1 == true && $b2 == true) or
($t2 == true && $b1 == true) or
($t2 == true && $b2 == true)
)

= is assignment operator == is comparison operator.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.