If else statement in php ~ PinoySourceCode

Friday, April 25, 2014

If else statement in php

if statement is use to check condition if condition is true then body of your code will be  execute.

Syntax
if (condition)
{
Code body
}

Exercise 1:

<?php
$x=20;
if($x>0)
echo "Number is true";
?>

Output
===============

Number is true
===============
if else statement

if else statement is use check the condition, if condition is true then the result will be execute,else if the condition is false.

Syntax

if (condition)
{
Code;
}
else
{
Code;
}

Exercise 2:

<?php

$x=25;
if($x>0)
echo "true";
else
echo “False”;
?>

Output
===============
true
===============

elseif statement

if you have one more condition then use elseif statement.

Syntax:

if (condition)
{
Code;
}
elseif (condition)
{
Code;
}
else
{
Code;
}


Exercise 3:

<?php

$x=25;
$y=45;
if($x>$y)
echo "First Number is Greater";
elseif($x<$y)
echo "Second Number is Greader";
else
echo "Both Number is equal";

?>

Output:
====================
Second Number is Greader
====================

Related Posts:

  • Array in PHP Suppose we want to store 100 data item. So we need 100 different variable. So this is very typical work for programmer to manage 100 different variab… Read More
  • If else statement in php if statement is use to check condition if condition is true then body of your code will be  execute.Syntaxif (condition){Code body}Exercise 1:&l… Read More
  • What is PHP? What is PHP?PHP is basically use for web developing dynamic website.Example of dynamic website are facebook.com,google.com etc.About Web DevelopmentW… Read More
  • HTML Form tag When creating textbox. labels,textarea , radio button etc. So this necessary to send these control value to the server.code:<form name="formanme" … Read More
  • PHP Loop Loop execute some statement many times till the condition is fullfill. There are three type or loops. these loops do same work execute statement man… Read More

0 (mga) komento:

Post a Comment

Get updates

Twitter Facebook Google Plus LinkedIn RSS Feed Email

Get Free Updates in Your Email


Enter your email address:

Popular Posts

A visitor from Columbus viewed 'PinoySourceCode' 9 hrs 5 mins ago
A visitor from Jung-gu viewed 'PinoySourceCode' 23 hrs 59 mins ago
A visitor from Semnan viewed 'PinoySourceCode' 1 day 4 hrs ago
A visitor from Dhaka viewed 'PinoySourceCode' 1 day 21 hrs ago
A visitor from Abuja viewed 'PinoySourceCode' 2 days 15 hrs ago
A visitor from Charleston viewed 'Payroll system simple but functional using php ~ P' 2 days 16 hrs ago
A visitor from Dire dawa viewed 'PinoySourceCode' 4 days 13 hrs ago
A visitor from Chandigarh viewed 'PinoySourceCode' 4 days 16 hrs ago
A visitor from Abuja viewed 'PinoySourceCode' 6 days 12 hrs ago
A visitor from Accra viewed 'PinoySourceCode' 7 days 1 hr ago