php if else sample code
This code is for those, who are facing problem with php if else
if (condition): ?>
html code to run if condition is true
else: ?>
html code to run if condition is false
endif ?>
if(condition) { ?>
html code to run if condition is true
$var=1;
if($var == 2) {
echo “The if statement is true”;
// or any html code to run if condition is true
} else {
echo “The if statement is not true”;
// or any html code to run if condition is true
}
?>
$var=1;
$var2=1;
if($var == 2) {
echo “The if statement is true”;
}
elseif($var == $var2) {
echo “The second if statement is true”;
}
else {
echo “None of the first if statement where true”;
}
?>
if ( $number_three == 3 ) {
echo "The if statement evaluated to true";
} else {
echo "The if statement evaluated to false";
}
?>
Sample 1:
if (condition): ?>
html code to run if condition is true
else: ?>
html code to run if condition is false
endif ?>
Sample 2:
if(condition) { ?>
html code to run if condition is true
Sample 3:
$var=1;
if($var == 2) {
echo “The if statement is true”;
// or any html code to run if condition is true
} else {
echo “The if statement is not true”;
// or any html code to run if condition is true
}
?>
Sample 4:
The if…elseif…else Statement
$var=1;
$var2=1;
if($var == 2) {
echo “The if statement is true”;
}
elseif($var == $var2) {
echo “The second if statement is true”;
}
else {
echo “None of the first if statement where true”;
}
?>
Sample 5:
if ( $number_three == 3 ) {
echo "The if statement evaluated to true";
} else {
echo "The if statement evaluated to false";
}
?>