In if else structure we will examine a Boolean expression whether it is true or false.
If it is true the statements inside if block will be executed. If it is false the statements inside the else part is executed.
Sample1.php
<?php
$condition=true;
if($condition)
{
echo 'this is true part'.'<br>';
echo 'the condition is true'.'<br>';
}else{
echo 'this is false part'.'<br>';
echo 'the condition is part'.'<br>';
}
?>
Output:
this is true part
the condition is true
checking a variable is null or not null in php.
<?php
$name="Muthu karthikeyan";
if(!is_null($name))
{
echo "name is defined <br>";
echo "your name is $name <br>";
}
else{
echo "name is not defined it is null";
}
?>
Output:
name is defined
your name is Muthu karthikeyan.
Checking using isset function.
<?php
$name="Muthu karthikeyan";
if(isset($name))
{
echo "name is defined <br>";
echo "your name is $name <br>";
}
else{
echo "name is not defined it is null";
}
?>
Output:
name is defined
your name is Muthu karthikeyan
checking using empty property.
<?php
$name="Muthu karthikeyan";
if(!empty($name))
{
echo "name is defined <br>";
echo "your name is $name <br>";
}
else{
echo "name is not defined it is null";
}
?>
Output:
name is defined
your name is Muthu karthikeyan.
If condition using number value.
Sample3.php.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="vote.php">
<P> please Enter your age:
<input type="text" name="txtAge" ></p>
<P> <input type="submit" name="submit" value="submit">
</p>
</form>
</body>
</html>
Vote.php.
<?php
$age=$_REQUEST["txtAge"];
if ($age>=18){
echo "your are eligible for vote";
}
else{
echo "not eligible for vote";
}
?>
Output:
Thank you
Muthu karthikeyan.
Contact:91 9629329142
Email:muthu.vaelai@gmail.com.
Madurai, Tamilnad, India.
No comments:
Post a Comment