This content originally appeared on DEV Community and was authored by Baransel
We can evaluate and combine multiple comparisons with logical operators. For example, we make a comparison of whether a variable is greater than 0 or less than 100 thanks to logical operators.
Let's show the logical operators in a table:
Operator | Name | Usage | Explanation |
---|---|---|---|
! | Negative | !$a | Returns true if the value of $a is negative, or the other way around. |
&& | And | $a && $b | If the value of $a and $b is positive, TRUE returns positive, if either is negative, returns FALSE. |
|| | Or | $a || $b | Returns positive if the value of $a or the value of $b is positive. It is enough that one or both are positive. |
In an example of these, we said at the beginning; Let's compare the value of a variable "if it is greater than 0 and less than 100". The condition we apply for this is as follows: $a > 0 && $a < 100
This means if the variable $a
is greater than 0 and less than 100. If the number in $a
is between 0 and 100, the result of this condition will be positive.
Follow my blog for more baransel.dev.
This content originally appeared on DEV Community and was authored by Baransel
Baransel | Sciencx (2021-09-02T16:15:06+00:00) What is the logical operators in PHP.. Retrieved from https://www.scien.cx/2021/09/02/what-is-the-logical-operators-in-php/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.