Sharp Tutorial
if else in php

Python

Java

C

C++

HTML/CSS

Java Script

PHP

SQL

C Programs

PHP Introduction

  • PHP home
  • PHP introduction
  • How to install and run
  • Syntax and Rule in PHP
  • Data type and operator
  • If else in php
  • Loop in php
  • Array in php
  • Sring in php
  • Function in php
  • Include in php

Working with Forms

  • Get and Post
  • Get Form input into PHP
  • Form Validation

PHP with MySQl

  • Connect PHP & Mysql
  • Insert using PHP Mysql
  • Select using PHP MySql
  • Delete Update using PHP Mysql
  • Login Page Example in PHP

Advanced PHP

  • Session in PHP
  • Cookies in PHP
  • File Handling in PHP
  • File Upload/Download PH

Object Oriented PHP

  • Class Obejct in PHP
  • Constructor in PHP
  • Destructor in PHP
  • Inheritance in PHP

If else in PHP

PHP uses if else to excute the block based on given condition is true or false. Else is the optional part of if which executes when given condition in if is false.

Multiple if condition , nested if or if else ladder may be used to achieve the complex scenario.

PHP Program based on if else

 <html>
<body bgcolor="gray">
<center>
<?php
$n=43;
if($n%2==0)
{
echo "Even no ";
}
else
{
echo "Odd no";
}
?>
<center>
</body>
</html>

output of the above program is odd no as we know 43 is not devided by 2 .Later we will take input from user.

Multiple If

 <html>
<body bgcolor="gray">
<center>
<?php
$n=50;
if($n%5==0)
{
echo "No is devided by 5";
}
if($n%10==0)
{
echo" No is devided by 10";
}
if($n%20 ==0)
{
echo"No is devided by 20";
}
if($n%50==0)
{
echo" No is devided by 50";
}
?>
</center>
</body>
</html>

output of the above program is no is devided by 5

no is devided by 10

no is devided by 50 [ no devided by 20 is not true].

Else if

 <html>
<?php
if(<condition 1>)
{
//if block executes if condition 1 is true.
}
else if(<condition 2>)
{
// this block executes if condition 1 is false and condition 2 is true.
}
else{
//this block executes if condtion 1 and condition 2 both are false.
}
?>
</html>

Nested if

 <html>
<?php
if(<condition 1>)
{
//echo"this executes if the condition 1 is true";
if(<condtion2>)
{
//echo" this block executes when condtion1 and condtion 2 both are true";
}
// echo " this is outside inner if so executes if condition 1 is true
}
?>
<html>

Enquiry about Course

Ask your Question

Click Here

Sharp (2) Tutorials

Video/ C Introduction

Watch video in full size

Video tutorial

Follow by Email
Facebook
Facebook
fb-share-icon
YouTube
Copyright © Sharp Tutorial
Build with WordPress
Wordpress Social Share Plugin powered by Ultimatelysocial
Sharp Tutorial