PDA

View Full Version : If statement problems


Jacobb123
06-04-2008, 08:01 PM
I can't get this if statement to work. It works if the || is not in there but not for both


if (($value['title']!=='Enter the USPS User ID') || ($value['title']!=='Which server to use') ){

$keys .= '<b>' . $value['title'] . '</b><br>' . $value['description'] . '<br>';

}

The full function puts the values inside the if statement into an array but with the above if/or statement it keep putting in the values but if I take the or part it work fine just for the one value. Why??...this is driving me nuts!!!!

angst
06-04-2008, 08:06 PM
hmm, I've into this issue a few times before.
and I've found then when using ! ( NOT ) together with &&/|| ( AND / OR ) it causes issues. you best bet maybe to break these appear and run two statements.

derzok
06-04-2008, 08:20 PM
Break it down:


<?
$a = 'a';

if($a !== 'x' || $a !== 'y') {
Print "Inside if\n";
}
?>


Think of it this way:
1) $a MUST not equal X
2) $a MUST not equal y.

If either 1 OR 2 is true (which will always be the case, since $a will never equal both x and y), then the inside is evaluated.

You probably want to switch your OR to an AND. This is called De Morgan's law: http://en.wikipedia.org/wiki/De_Morgan%27s_laws

angst
06-04-2008, 08:24 PM
hmm, i just did a test exactly like that and still couldn't make it work right, the logic is simple. and seems like it should work.

whizard
06-04-2008, 09:24 PM
try != instead of !==

I <3 Lamp
06-04-2008, 09:46 PM
The answer has already been provided you've just chosen to ignore it. Use && instead of ||

oesxyl
06-04-2008, 09:51 PM
Break it down:


<?
$a = 'a';

if($a !== 'x' || $a !== 'y') {
Print "Inside if\n";
}
?>


Think of it this way:
1) $a MUST not equal X
2) $a MUST not equal y.

If either 1 OR 2 is true (which will always be the case, since $a will never equal both x and y), then the inside is evaluated.

You probably want to switch your OR to an AND. This is called De Morgan's law: http://en.wikipedia.org/wiki/De_Morgan%27s_laws
what's wrong with it? it work how I expect.

PS: btw this is a tautology:
http://en.wikipedia.org/wiki/Tautology_%28logic%29

regards