34,333
edits
Changes
→PHP Logical Operators
== 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, allowing desicions to be made about how a script should proceed.
''If x $var is less than 10 25 AND y $var2 is greater than 20 45 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 $var1 < 1025) && (y $var2 > 2045)document.write ("Message")echo 'Our expression is true';
</pre>
Similarly , if our sentence was to read:
''If x $var1 is less than 10 25 OR y $var2 is greater than 20 45 display a message.''
Then we would replace the "OR" with the JavaScript equavalent ||:
<pre>
if ((x $var1 < 1025) || (y $var2 > 2045)document.write ("Message")echo 'Our expression is true';
</pre>
The final Logical Operator is the NOT operator which simply inverts the result of an expression. The ! character represents the NOT operatoer operater and can be used as follows:
<pre>
(10 > 1) // returns ''true''
!(10 > 1) // retruns returns ''false'' because we have inverted the result with the logical NOT
</pre>