PHP if -- else statement in conditions

If statement enable programmer to execute a script only when a condition is true.
And Else enable to quickly execute a script when the condition fails.

PHP Code:
<?php
$myname = "Smith" ;
if ( $myname == "Smith" ) {
echo "hello ! Your are Smith"; // wil be displayed only if condition is true
} else
{
echo "hello ! Your are not Smith";
// wil be displayed only if condition is false
}
?>
This may also be writed like this:
<?php
$myname = "Smith" ;
if ( $myname == "Smith" )
echo "hello ! Your are Smith"; // wil be displayed only if condition is true
else

echo "hello ! Your are not Smith";
// wil be displayed only if condition is false
?>
"{" and "}" can be deleted because there is only one line in if and else statements. If you want to create many lines of script, so then you should use"{" and "}":

PHP Code:
<?php
$myname = "Smith" ;
if ( $myname == "Smith" )
{
echo "hello ! Your are Smith"; // wil be displayed only if condition is true
echo "You are wellcome";
} else

echo "hello ! Your are not Smith";
// wil be displayed only if condition is false
?>
Here the "{" and "}" are necessary in the if statement, but not necessary in the else one as else statement has only one line of code.

2 comments:

Guild Wars 2 Gold said...


Your own card is merely beautiful -- and what a pleasant reward. Any kind of lady will be excited to get this specific.
Many thanks for a person ideas.
cheap Diablo iii gold


GW2 Cd key

winter lijia said...

Hello everyone, I am new here. Do you want to buy qualitied things at low price? Are you a WoW fan? I want to make some friends who are good at MMORPG. And here you are a reliable website to buy WoW gold. The address is http://www.gold4power.com