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 decisions to be made about how a script should proceed.The logical operators supported by PHP are listed in the following table: <table border="1" cellspacing="0" width="100%"><tr style="background:#efefef;"><th>Operator<th>Type<th>Description<th>Examples</th><tr><td>&&<td>AND<td>Performs a logical "AND" operation.<td>if (($var1 < 25) && ($var2 > 45))</td></tr><tr><td>||<td>OR<td>Performs a logical "OR" operation.<td>if (($var1 < 25) || ($var2 > 45))</td></tr><tr><td>xor<td>XOR<td>Performs a logical "XOR" (exclusive OR) operation.<td>if (($var1 < 25) xor ($var1 > 45))</td></tr></table>
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: