ArticleCity.com - free articles for reprint.

SEARCH

SITE MENU

CATEGORIES

Keyword Search


Article Title
Author's Name


PHP Logic
 by: Izzat Youssif




If else statements

Let's look at an example

if ($lesson = "html") {
echo "Welcome to html";
}

The above statement tells php to display Welcome to html if our Lesson variable is equal to html.
The condition is always stated next to the if in () . The results are stated after the { and } tells php that you are ending the if statement.

Next let's look at an else example

if ($lesson = "html") {
echo "Welcome to html";
}
elseif ($lesson = "php") {
echo "Welcome to php";
}
else {
echo "No lesson chosen";
}

Else statement came after an if statement. Notice else came in elseif and else formate. Elseif looks for other conditions if they existed. Else is the result as a last resort, if no other option is available. Both elseif and else follow the same structure as if statements.

Next , we'll talk about loops statments

The first type of loop statements are while statements

Let's look at an example below

$ls = 0;
while ($ls < 5) {
echo "$lesson" ;
$ls++;
}

While statement are used to loop through a collection of records or data. The above statement simply at the number of our $ls variable and from that number prints the chosen lesson. Again following the same structure as if else statements, condition next to the while and condition below { and ending with . The only differences is we incremented the variable within the statement.

Next we'll discuss for statements

For statements are used in the same essence as while statment, expect more emphasis is put on the variable as you'll in the example below.

for ($ls=0;$ls<$totalls;$ls++)
{
echo $ls['lesson'];
}

The above example, declares the ls variable again and compares it to total numbers of lessons. While ls is less than total number of lessons, we tell php to increment. Again following the same structure as if else statements, condition next to the for and condition below { and ending with } .

About The Author

Izzat Youssif is an online web designer and developer offering low cost website design and development service, as well as free website design and development. visit http://websitedevelopmentanddesign.com for more details!

This article was posted on October 13, 2006

 


Pregnancy.org Case Study - Drupalcon

Eric Schmidt on Microsoft's Plans for Online Video Space

Controlling Your Visitors' Eyes

How to Use the Templates for Web Applications in MS Visual Studio

 

<< Back to "Web Design And Development" Index


Disclaimer: The information presented and opinions expressed herein are those of the authors
and do not necessarily represent the views of ArticleCity.com and/or its partners.



Search || Bulk Article Submission || Submit An Article || Syndicate Articles
Free Videos || Advertising|| Home || Privacy Policy
Terms of Use || Link To Us || Site Map || Contact Us

This site uses Thumbshots previews