|
if else Statement in php |
This is tutorial of “if statement” within php. Now, “if statement” is to compare data’s and parameters or to evaluate something which is true or false,thus fulfills the true condition.For example If i do this that will be outcome and if i don’t do this that will be outcome.
Code for if_if else statement (Screenshot1):-
|
if _ if else Statement (Screenshot 1) |
<?php
if (1)
{
echo ' TRUE.';
}
else
{
echo 'FALSE.';
}
?>
Output (Screenshot2) :-
|
Screenshot2 |
In this code of “if and else statement”, code will be evaluated that are inside the curly {} brackets.I have echoed “True” when value is 1.In general, 1 itself is a statement of programming that will evaluate “True” as an echo statement,otherwise it will follow “elsestatement” that will echo “False” as an echo statement if wechange value 1 to any number
Code for if_if else statement(Screenshot3) :-
|
If else Statement Screenshot3 |
<?php
if (0)
{
echo ' TRUE.';
}
else
{
echo 'FALSE.';
}
?>
Output (Screenshot4) :-
|
Screenshot4 |
In this example we are changing value 1 to 0. 0 itself is a statementof programming that will output “False”.
Code for if_if else Statement (Screenshot5) :-
|
Screenshot5 |
<?php
If (true)
{
echo ' TRUE.';
}
else
{
echo 'FALSE.';
}
?>
Output (Screenshot6) :-
|
Screenshot6 |
In this example we are doing the same thing by changing variables to true values. Its evaluate “True” and echoes it.
Code for if_if else Statement (Screenshot7) :-
|
Screenshot7 |
<?php
if (false)
{
echo ' TRUE.';
}
else
{
echo 'FALSE.';
}
?>
Output (Screenshot8) :-
|
Screenshot8 |
In this example we are doing the same thing by changing variables to false values. Its evaluate “False” and echoes it. If “if_else statements” are used for comparison,then comparison operator such as double equal to (==) in if statement is used as shown below.
Code for if_if else statement with operators (Screenshot9) :-
|
Code for if_if else statement with operators (Screenshot9) :- |
<?php
if (1==1)
{
echo ' TRUE.';
}
else
{
echo 'FALSE.';
}
?>
Output (Screenshot10):-
|
Screenshot10 |
In this code we say 1 is equal to 1 which is true so it will echo out “True”.
Code for if_if else statement with operators and variables(Screenshot11) :-
|
Screenshot11 |
<?php
$text = 'Something';
if ($text=='Something')
{
echo 'TRUE.';
}
else
{
echo 'FALSE.';
}
?>
output (Screenshot12):-
|
Screenshot12 |
In this example of code we are taking varibles “if statement” we aredefining variables and in different condition we are putting variables to compare and check which are true statements and which are false statements.
Code for if_if else statement with operators and variables(Screenshot13) :-
|
Screenshot13 |
<?php
$text = 'Something';
if ($text=='Something else')
{
echo 'TRUE.';
}
else
{
echo 'FALSE.';
}
?>
output (Screenshot14):-
|
Screenshot14 |
In this example of “if statement” we declare variable $text as “Something” which will echo out “False”. Here, the “if statement” fulfills “Something else” and echoes “True” but in actual value is not “Something else” its “Something”.So this the basic structure of “if_else statement”.We can use if_else statement with keywords of if and else quiet easily! !
No comments:
Post a Comment
Thanks For Comment Will get you Soon..