Boolean Logic and PHP Conditions

Introduction
This is part 6 of my series, Basics of PHP. In this part of the series, we apply Boolean logic to PHP conditions.

Note: If you can’t see the code or if you think something is missing (broken link, missing image), contact me at [email protected]. That is, contact me for the smallest problem you have as you read. are the first elements around HTML). In the condition, (if the parentheses) there is only one expression, which is, $me == “long”. If this happens to be true, then the block will be executed. The above if-edition is valid and

if
{
echo ‘I’m long’;
}

For this second, if the statement is to be executed, you do not need the creation of the variable and its assignment. Read and try the following code:

Let’s look at a case where the false condition occurs. Consider the following code:

If the block (curly string) in the code above will not be executed, because a false condition follows, because the value of the invariant, $me, is short. and not “long”. The predicted if statement is equivalent to:

The if block can only be executed if the condition is true. This is not an execution in the last case.

More than one expression in a Condition
You can have more than one expression in a condition. In this part of the series, I consider the maximum condition of two expressions. Each statement results in either true or false. Words are combined with the operators AND, OR, or NOT. The operator AND is typed, &&. The OR operator is typed as || . The NOT Operator is typed as! . &&, || , and ! they are called logical operators. With logical operators, the rules in the previous part of the sequence can be rewritten as:

AND
(false) && false
(false) && && && (true) = true

OR
(false) || (false) = false
(false) || (true) = true
(true) || (false) = true
(true) || (true) = true

NOT
!(false) = true
!(true) = false

Double- Expression examples
If the block in the following code will not be:

A practical example is used for the above code:

“long” is assigned to the variable, $te, and also for variables, $me. The first condition in falsities, the second in truths. (false) &&(true) false returns the effective value for the Boolean condition. So the block is not executed.

If the block occurs in the following code:

A practical example is written for the above code:

Read about the above code. Try it. The first statement results in falsities; according to the truth The effective condition is true because it is true because it returns true.

NOT Examples
If the block is executed in the following code:< /p>

If the block is executed , if the condition is true. !(false) gives true. If the condition is false, then there will be no block.

A practical example is written in the above code:

seif and else
You can still add elseif and other subjects to the examples of the upper code, which we learned in one of the previous parts.

Let us stop here and continue in the second part of the series.

Leave a Reply

Your email address will not be published. Required fields are marked *