Welcome to Egypt Forums Mark forums read | Egypt Main Page
Egypt Forums
Arabic Movies



Classes & Source Code Thread, Lesosn : PHP If Statement in PHP; Lesosn : PHP If Statement The if, elseif and else statements in PHP are used to perform different actions based ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=4988


Reply
LinkBack Thread Tools Display Modes
Lesosn : PHP If Statement
 
 
The God Father
Developer's Avatar

Reply With Quote
 
Join Date: Jul 2008
Location: NDC
Posts: 5,425
22-10-2008, 04:40 AM
 
Lesosn : PHP If Statement

The if, elseif and else statements in PHP are used to perform different actions based on different conditions.

Conditional Statements

Very often when you write code, you want to perform different actions for different decisions.



You can use conditional statements in your code to do this.
  • if...else statement - use this statement if you want to execute a set of code when a condition is true and another if the condition is not true
  • elseif statement - is used with the if...else statement to execute a set of code if one of several condition are true
The If...Else Statement

If you want to execute some code if a condition is true and another code if a condition is false, use the if....else statement.
Syntax

PHP Code:
if (condition)  code to be executed if condition is true;else  code to be executed if condition is false;
Example

the following i'll write if you have entered egypt so go one and if you don't you will have error mass

[
PHP Code:
<html><body>
<?php
$var
= " egypt ";
if(
$var == "egypt")
{
echo
" Go on ";
}
else
{
Error mass please try again later !
}

?>
</body></html>
To be Contuined
__________________
I Love Walking In The Rain Cuz Nobody Know I'm Crying !!

Last edited by Developer; 22-10-2008 at 04:47 AM..
 
 
 
 
The God Father
Developer's Avatar

Reply With Quote
 
Join Date: Jul 2008
Location: NDC
Posts: 5,425
22-10-2008, 06:36 PM
 
If more than one line should be executed if a condition is true/false, the lines should be enclosed within curly braces:


PHP Code:
<html>
<body>     
<?php
$d
= "Fri";
if (
$d=="Fri")
  {
echo
" Have A Nice Weekend <br>
Welcome To Our Village "
;
  }
?>  
</body>
</html>
The ElseIf Statement

If you want to execute some code if one of several conditions are true use the elseif statement
Syntax

PHP Code:
if (condition)
  
code to be executed if condition is true;
elseif (
condition)
  
code to be executed if condition is true;
else
  
code to be executed if condition is false;
</i>Example

This following example will approve to you if you have entered in variable day Friday have a nice weekend else if you have entered Sunday write in browser Good luck else this two conditions write in browser you have entered wrong letters

PHP Code:
<html>
<body>  
<?php
$day
= " Friday ";
if(
$day == "Friday")
(
echo
" Have A Nice Weekend ";
}
elseif(
$day == "Sunday")
{
echo
" Good Luck ";
}
else
{
echo
" you have entered wrong letters  ";
}
?>     
</body>
</html>

result here will be Have A Nice Weekend Because Variable $day equal to Friday if you change it To Sunday result will be Good Luck Etc...
Good Luck All Hope Lesson was useful any Q Just Tell me in pm or here

Copyright @ Egypt.com


system
__________________
I Love Walking In The Rain Cuz Nobody Know I'm Crying !!

Last edited by Developer; 22-10-2008 at 06:39 PM..
 
 
 
Reply

Classes & Source Code Thread, Lesosn : PHP If Statement in PHP; Lesosn : PHP If Statement The if, elseif and else statements in PHP are used to perform different actions based ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=4988


Bookmarks

Tags
lesosn, php, statement


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
European officials refused Egyptian HR statement SABRAWY News 0 22-01-2008 08:18 PM