Changes

Jump to: navigation, search

PHP Operators

1,315 bytes added, 13:17, 31 May 2007
PHP Comparison Operators
</table>
 
== PHP Logical Operators ==
 
''Logical Operators'' are also known as ''Boolean Operators'' because they evaluate parts of an expression and return a ''true'' or ''false'' value.
 
Perhaps the best way to understand how logical operators work is to construct a sentence rather than to look at a script example right away. Let's assume we want to check some aspect of two variables named x and y. Our sentence might read:
 
''If x is less than 10 AND y is greater than 20 display a message.''
 
Here the logical operator is the "AND" part of the sentence. If we were to express this in JavaScript we would use the comparision operators we covered earlier together with the && logical operator:
 
<pre>
 
if ((x < 10) && (y > 20)
document.write ("Message");
 
</pre>
 
Similarly if our sentence read:
 
''If x is less than 10 OR y is greater than 20 display a message.''
 
Then we would replace the "OR" with the JavaScript equavalent ||:
 
<pre>
 
if ((x < 10) || (y > 20)
document.write ("Message");
 
</pre>
 
The final Logical Operator is the NOT operator which simply inverts the result of an expression. The ! character represents the NOT operatoer and can be used as follows:
 
<pre>
 
(10 > 1) // returns ''true''
 
!(10 > 1) // retruns ''false'' because we have inverted the result with the logical NOT
 
</pre>
== PHP Increment and Decrement Operators ==

Navigation menu