Need help on this Php If statement:If either is true,the other is not false

Hi guys,
Hope you’re all doing just fine . I’d be grateful if you you can help out with this:


if ( ($country != 'Canada') || ($country != 'United States') ) {

deny all,except these two countries(either one)
exit;
}

Currently the code has to deny one or the other(whatever returns false). If am from Canada,am denied because am not from the United States(and vice versa).

I tried it with an array and xor but to no result. May be am too tired i can’t see the obvious.

Try this:


	<?php
	echo '<dl>';
	$continent = array('Canada', 'United States', 'Brazil', 'Mexico');
	foreach($continent as $country):
		echo '<dt><br />Country: ' .$country .'<br /></dt>'; 

		if ( ($country === 'Canada') OR ($country === 'United States') )
		{ 
			echo '<dd>';
			if ('Canada' === $country)
			{
				echo 'Denied because from <b>Canada</b> and not from the <b>United States</b>';
			}else{
				echo 'Denied because from <b>United States</b> and not from the <b>Canada</b>.';
			}
			echo '<br />deny either Canada OR United States'; 
			echo '</dd>';
		} 
		
		if ( ($country != 'Canada') AND ($country != 'United States') )
		{ 
			echo '<dd>';
			echo 'NEITHER Canada NOR United States';
			echo '</dd>';
		} 
	endforeach;	
	echo '</dl>';
?>	

.

Do the logic math.
If your word is… “Banana”
IF…TRUE OR TRUE = TRUE.
If your word is “Canada”
IF…FALSE OR TRUE = TRUE.
If your word is “United States”
IF…TRUE OR FALSE = TRUE.

You dont want OR. Assuming your test to equal 1 when the word

1 1 1
1 0 0
0 1 0
0 0 0 (Impossible Case)
Is AND.


if ( ($country != 'Canada') && ($country != 'United States') ) {

http://en.wikipedia.org/wiki/De_Morgan&#37;27s_laws

:slight_smile:

Indeed. Couldnt remember the law name off the top of my head, hence the logic table. :stuck_out_tongue: