100% found this document useful (1 vote)
108 views

PHP Conditional Statements

This document discusses conditional statements in PHP. It defines conditional statements as code used to perform different actions based on different conditions. It describes the main types of conditional statements in PHP: if statements, if/else statements, and if/elseif/else statements. If statements execute code if a single condition is true, while if/else statements execute one block of code if the condition is true and another block if it is false. The document provides syntax examples and explanations of how each type of conditional statement works in PHP code.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
108 views

PHP Conditional Statements

This document discusses conditional statements in PHP. It defines conditional statements as code used to perform different actions based on different conditions. It describes the main types of conditional statements in PHP: if statements, if/else statements, and if/elseif/else statements. If statements execute code if a single condition is true, while if/else statements execute one block of code if the condition is true and another block if it is false. The document provides syntax examples and explanations of how each type of conditional statement works in PHP code.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

PHP Conditional

Statements
Prepared by: Yvonn Kyla V. Magallon

Source: w3schools.com
Learning Objectives
1.To understand the importance of conditional
statement
2.To know the different types of conditional
statements in PHP
3.To know the fundamental logic creation using
conditional statement
Conditional Statements
Conditional Statements are
used to perform different
actions based on different
conditions.
Types of PHP Conditional Statements

1.if statement
2.if…else statement
3.if…elseif…else statement
4.switch statement
The if statement
The if statement
executes some code if
one condition is true.
if(condition){
code to be executed if condition is true;
}

Syntax
if(condition){
code to be executed
if condition is true;
}
if(condition){
code to be executed if condition is true;
}

Example
<?php
$x = 20;
$y = 10;
if($x > $y){
echo “$x is greater
than $y”;
}
?>
if(condition){
code to be executed if condition is true;
}

Output
20 is greater than 10
if(condition){
code to be executed if condition is true;
}

Example
<?php
$x = 10;
$y = 20;
if($x > $y){
echo “$x is greater
than $y”;
}
?>
The if…else statement
The if…else statement
executes some code if a
condition is true and
another code if that
condition is false.
if(condition){
code to be executed if condition is true;
}

Syntax
if(condition){
code to be executed if
condition is true;
}else{
code to be executed if
condition is false;
}
if(condition){
code to be executed if condition is true;
}

Example
<?php
$x = 10;
$y = 20;
 if ($x > $y){
echo “$x is greater than $y”;
}else{
echo “$x is less than $y”;
}
?>
if(condition){
code to be executed if condition is true;
}

Output
10 is less than 20
Must remember:
1.Conditional Statements are used to perform
different actions based on different
conditions.
2. The if statement executes some code if one
condition is true.
3. The if…else statement executes some code if a
condition is true and another code if that
condition is false.
Thank you for
listening!

You might also like