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:

  • 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
  • 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
  • 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
  • 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
  • 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 Nairobi viewed 'PinoySourceCode' 5 hrs 26 mins ago
A visitor from Laval viewed 'PinoySourceCode' 9 hrs 55 mins ago
A visitor from Kigali viewed 'PinoySourceCode' 9 hrs 56 mins ago
A visitor from St petersburg viewed 'PinoySourceCode' 23 hrs 13 mins ago
A visitor from Hamadan viewed 'PinoySourceCode' 23 hrs 14 mins ago
A visitor from California viewed 'PinoySourceCode' 23 hrs 15 mins ago
A visitor from Ashburn viewed 'PinoySourceCode' 23 hrs 15 mins ago
A visitor from Toliara viewed 'PinoySourceCode' 1 day 18 hrs ago
A visitor from Ashburn viewed 'PinoySourceCode' 2 days 18 hrs ago
A visitor from Indonesia viewed 'PinoySourceCode' 4 days ago