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
====================

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