| Home | Free Articles for Your Site | Submit an Article | Advertise | Link to Us | Search | Contact Us |
This site is an archive of old articles

    SEARCH ARTICLES
    Custom Search


vertical line

Article Surfing Archive



PHP Logic - Articles Surfing


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 } .

Submitted by:

Izzat Youssif

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!



        RELATED SITES






https://articlesurfing.org/web_development/php_logic.html

Copyright © 1995 - Photius Coutsoukis (All Rights Reserved).










ARTICLE CATEGORIES

Aging
Arts and Crafts
Auto and Trucks
Automotive
Business
Business and Finance
Cancer Survival
Career
Classifieds
Computers and Internet
Computers and Technology
Cooking
Culture
Education
Education #2
Entertainment
Etiquette
Family
Finances
Food and Drink
Food and Drink B
Gadgets and Gizmos
Gardening
Health
Hobbies
Home Improvement
Home Management
Humor
Internet
Jobs
Kids and Teens
Learning Languages
Leadership
Legal
Legal B
Marketing
Marketing B
Medical Business
Medicines and Remedies
Music and Movies
Online Business
Opinions
Parenting
Parenting B
Pets
Pets and Animals
Poetry
Politics
Politics and Government
Real Estate
Recreation
Recreation and Sports
Science
Self Help
Self Improvement
Short Stories
Site Promotion
Society
Sports
Travel and Leisure
Travel Part B
Web Development
Wellness, Fitness and Diet
World Affairs
Writing
Writing B