Whether you learn PHP or another language, iteration through loops is
a part of every modern programming language. PHP loops involve the
keywords while, do...while, for, and foreach. Each one expresses its
condition in parentheses and the operational aspect of its function in
curly braces. So the basic syntax of any loop in PHP is:
An example of a while loop in PHP would read:
echo "The number is " . $i . "<br />";
As long as the condition is true, the loop will execute.
A for loop follows the pattern:
for ($i=1; $i<=5; $i++)
echo "The number is " . $i . "<br />";
The logic of this loop is fairly straightforward. The first value is the beginning, the second is the end, and the third is the increment by which the loop should proceed. The '++' symbol is used to add one to the value of a variable. Its complement '--' is used to subtract one. Both the beginning and end values are inclusive, so this loop progresses from 1 to 5 inclusively.
The foreach loop is used to progress through the elements of an array. The value of an array element is assigned the variable name used in the operation. The loop then progresses through the elements of the array, processing each element according to the operational aspect of the loop, and terminates softly when it reaches the limit of array elements.
A do...while loop forms the exception to the pattern of PHP loops. It looks this:
echo "The number is " . $i . "<br />";
Note that the while condition comes after the operational part of the loop. This loop performs the same operation as the for loop shown above. The output is:
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5
This is the start of syntax in PHP. There is more to learning PHP, to be sure, but this gets you started. Be sure to read the other PHP tutorials in this series to learn PHP thoroughly.
Get Ubuntu Linux: Download, Request, or Order Ubuntu Ubuntu can be downloaded or ordered and is available in a couple of versions: 6.06 (Dapper Drake) and 7.04 (Feisty Fawn). Which you use depends on the software you need. This page shows you from where you can download, request, or buy Ubuntu.
Ubuntu vs Windows Vista Ubuntu had many Windows Vista features almost a year before Microsoft released it. Here is how Ubuntu compares to Windows Vista.
Resizing a Windows Installation Resizing a Windows installation is easy with the Ubuntu installer. Installing Ubuntu in parallel to a Windows installation is called 'dual booting' and is a good idea. Here is how to do it.
A Brief History of Ubuntu Ubuntu's history started with Debian GNU/Linux but has since outgrown it. Here is a brief look at Ubuntu's past and how things stand today.
Booting Windows Instead of Ubuntu by Default Grub boots Ubuntu by default. But if you want to make Windows your default operating system without losing Ubuntu, all you need do is change a number in Grub's configuration file. Here is how.
A Primer for Installing Ubuntu Installing Ubuntu should be as easy as possible, and the best guides for this are provided here at Easy Ubuntu Linux. But all the online resources in the world do not help you offline. For this reason, we are providing this PDF primer to help you install Ubuntu.
Image Handling With Ubuntu Ubuntu's image handling surpasses those of other operating systems. Whether you just need to look at your pictures or create first-rate graphics, Ubuntu offers a program to meet your needs.
Photo Editing With the GIMP Ubuntu comes with the GIMP already installed. Here is a brief tutorial on how to edit photos with the GIMP.
Configure Apache Web Server on Ubuntu Apache is a web server available for Ubuntu. With it you can serve web pages from a computer. Here is how to setup Apache as a web server on Ubuntu.
Apache Web Server Configuration on Ubuntu Apache on Ubuntu is a web server that enables you to serve web pages. How well those web pages are served depends on the configuration you use. Here is detailed information on the default configuration of the Apache web server on Ubuntu.
Reading the php.ini File from Ubuntu PHP is one of the web's main languages for development. Understanding how to configure PHP
allows you to create web pages
dynamically on Apache.
The Easy Ubuntu Blog Ubuntu is not always easy. But Easy Ubuntu Linux helps make it that way. Keep it easy with the Easy Ubuntu blog.
Installing a LAMP Server on Ubuntu A LAMP server is one of the most pervasive types of servers on the Internet, but many people find installing LAMP servers difficult. Here is how to install a LAMP server on Ubuntu.
Installing Samba on Ubuntu Samba is the main Ubuntu file sharing server. It allows you to share files with others from your computer. Here is how to use Ubuntu to share files with Samba.
Configuring Samba on Ubuntu I Samba is a file sharing server for Ubuntu Linux. It allows filesharing with others from your computer. This guide shows how to configure Samba on Ubuntu.
Configuring Samba on Ubuntu II Samba is a file sharing server for Ubuntu Linux. It allows filesharing with others from your computer. This is the second page of a guide that shows how to configure Samba on Ubuntu.
Configuring Samba on Ubuntu III: [globals] Samba is a file sharing server for Ubuntu Linux. The [globals] header is part of the Samba configuration file. This guide shows how to configure the [globals] section of the Samba configuration on Ubuntu.
Configuring Samba on Ubuntu IV: [homes] Samba is a file sharing server for Ubuntu Linux. The [homes] header is part of the Samba configuration file. This guide shows how to configure the [homes] section of the Samba configuration on Ubuntu.
Configuring Samba on Ubuntu V: [printers] Samba also functions as a printer managing server for Ubuntu Linux. The [printers] header is part of the Samba configuration file. This guide shows how to configure the [printers] section of the Samba configuration.
Resizing a Windows Installation: A Caution Resizing a Windows installation is easy with the Ubuntu installer. Installing Ubuntu in parallel to a Windows installation is called 'dual booting' and is a good idea. Here is how to do it.
Credit Card Validation Before Processing Processing credit cards is a fundamental process when you do ecommerce on Apache. Here we walk through some of the more common options for credit card processing on Ubuntu.
Credit Card Processing Choices Processing credit cards is a fundamental process when you do ecommerce on Apache. Here we walk through some of the more common options for credit card processing on Ubuntu.
Apache Web Hosting Apache is the main web server provided by web hosting companies. Here are recommendations on which Apache web hosting company to use for your Apache web host.
Linux Notebooks Linux notebooks are not as rare as they once were. It is nonetheless possible to buy a notebook and find that you cannot install Linux on it. Here is a series of guides for how to install Linux on different notebooks.
PCI DSS - What is PCI DSS PCI DSS is one of the most important elements of e-commerce. Even if you run your own credit card processing business, you would be forgiven for wondering 'What is PCI DSS?'. This cryptic abbreviation is explained here.
Sudoers - Registering Users in the Sudoers File Sudoers are those users who can gain administrative access to the system. Their names are listed in the sudoers file. Here is how to be so registered if your username is not in the sudoers file.
Sign Up for Gmail Sign up for Gmail and get several benefits for free. Here is how to sign up for Gmail for free.
Email Solutions on Ubuntu Linux Email solution on Linux vary according to how much control and accessibility you want to have. Here we see what is available
for email solutions under Ubuntu Linux.
Install Ubuntu 10.04 (Lucid Lynx) Install Ubuntu 10.04 (Lucid Lynx) with minimal fuss. Some choices in the installation process are better than others, and this installation guide will help you to install Ubuntu 10.04 (Lucid Lynx) with ease.
OpenOffice Writer OpenOffice Writer is the wordprocessing application of the OpenOffice office suite of productivity applications. Here are the basics of using OpenOffice Writer.
Unless otherwise stated, all material contained on this website is
copyrighted to Easy Ubuntu Linux.com. All rights are reserved. All
content is provided AS IS without any warranty of any kind for any
If you have a question or comment about Ubuntu or this site,
please send email to 'webmaster (at) easy-ubuntu-linux.com' (remove
single quotes and replace "@" for " (at) ").