StrongFaith II
Member
- Nov 23, 2010
- 307
- 2
Hey peoples !!
Today i'll show you how to use if() and else statements .
How to use if() statement
EX 1:
As we know when we use date() function on PHP , it shows "DAY/MONTH/10" (10 = year). Some peoples want to show it as "DAY/MONTH/2010" , well to do that we use if() statement , watch and learn :
EX 2:
Ehm , i thought about showing "Have a nice sunday" if today is sunday
Watch and learn :
How to use else statement
EX 1:
If year is not 2010 , and we want to show it 2011 we use else statement
Watch and learn :
EX 2:
If day is not sunday , it will show : "Have a nice day".
Watch and learn :
That was it peoples , hope you like it!
Rate tut ?/10
Thanks!!!!
StronGCoder.
Today i'll show you how to use if() and else statements .
How to use if() statement
EX 1:
As we know when we use date() function on PHP , it shows "DAY/MONTH/10" (10 = year). Some peoples want to show it as "DAY/MONTH/2010" , well to do that we use if() statement , watch and learn :
PHP:
<?php // start of PHP
echo date("d/m"); //shows only day and month
if(date("y") == "10") // if year is 10 (shows as 10 , means 2010)
{ // start of what does if() statement does.
echo "/2010"; // so , if year is 2010 , on date wont show 10 , it will show 2010.
} // end
//the following code will show : "DAY/MONTH/2010"
// end of PHP ?>
EX 2:
Ehm , i thought about showing "Have a nice sunday" if today is sunday
Watch and learn :
PHP:
<?php // start of PHP
$today_is = date("d"); // the day
if($today_is == "Sun") // if day is Sunday
{ // start of what if() statement does
echo "Have a nice sunday"; // so , if today is Sunday shows "Have a nice sunday"
} // end
// end of PHP ?>
How to use else statement
EX 1:
If year is not 2010 , and we want to show it 2011 we use else statement
Watch and learn :
PHP:
<?php // start of PHP
echo date("d/m"); //shows only day and month
if(date("y") == "10") // if year is 10 (shows as 10 , means 2010)
{ // start of what does if() statement does.
echo "/2010"; // so , if year is 2010 , on date wont show 10 , it will show 2010.
} // end
else // if year is not 2010
{ // start of what else statement will do , or show
echo "/2011"; // so , if year is not 2010 , shows /2011 :)
} // end
//the following code will show : "DAY/MONTH/2011" ONLY if year is not 2010.
// end of PHP ?>
EX 2:
If day is not sunday , it will show : "Have a nice day".
Watch and learn :
PHP:
<?php // start of PHP
$today_is = date("d"); // the day
if($today_is == "Sun") // if day is Sunday
{ // start of what if() statement does
echo "Have a nice sunday"; // so , if today is Sunday shows "Have a nice sunday"
} // end
else // if today is not sunday
{ // start of what else statement will do or show
echo "Have a nice day"; // so , if today is not sunday it will show "Have a nice day"
} // end
// end of PHP ?>
That was it peoples , hope you like it!
Rate tut ?/10
Thanks!!!!
StronGCoder.