Changes

Jump to: navigation, search

PHP Operators

4 bytes added, 19:25, 11 May 2009
PHP Logical Operators
The first step to understanding how logical operators work is to construct a sentence rather than to look at a script example right away. Let's assume we need to check some aspect of two variables named $var1 and $var2. Our sentence might read:
''If $var var1 is less than 25 AND $var2 is greater than 45 display a message.''
Here the logical operator is the "AND" part of the sentence. If we were to express this in PHP we would use the comparison operators we covered earlier together with the && logical operator:
<pre>
if (($var1 < 25) && ($var2 > 45))
echo 'Our expression is true';
<pre>
if (($var1 < 25) || ($var2 > 45))
echo 'Our expression is true';
<pre>
if (($var1 < 25) xor ($var2 var1 > 45))
echo 'Our expression is true';

Navigation menu