Conditional Statements in PHP: by Monika Singla
Conditional Statements in PHP: by Monika Singla
Statements in PHP
Conditional statements control the flow of execution in your PHP
code. They allow you to execute different code blocks based on
the evaluation of certain conditions. Let's dive in and explore
the various types of conditional statements available in PHP.
By monika singla
The if() and elseif() Condition Statements
1 if() Statement
2 elseif() Statement
3 else Statement
''' '''
$number = -5; session_start();
The switch statement begins with a variable If a match is found, the corresponding code
or expression to evaluate. block for that case is executed.
1 3
2 4
Condition
The loop continues to execute as long as the
specified condition remains true.
Iteration
The loop body is executed repeatedly, and the loop
counter is updated within the loop.
The do-while Statement in PHP
while() do-while()
The condition is checked before the loop body is The loop body is executed at least once, regardless
executed. If the condition is false, the loop body is of the condition, and the condition is checked after
never executed. the loop body is executed.
The for() Loop in PHP
Initialization
A variable is initialized before the loop begins. This variable is usually used
as the loop counter.
Condition
The condition is checked at the beginning of each iteration. The loop
continues to execute as long as the condition remains true.
Increment
The loop counter is incremented or decremented after each iteration.