PHP

 Home  Computers & Internet  Web Programming PHP
What is PHP?
Echo
Comments
Variables
Constants
Data Types
number_format()
Character Strings
Mathematical Operators
Comparison Operators
Logical Operators
Joining Strings
explode()
implode()
strtolower()
strtoupper()
strlen()
ucfirst()
ucwords()
strrev()
str_replace()
str_repeat()
trim()
strip_tags()
addslashes()
stripslashes()
strpos()
strrpos()
nl2br()
isset()
unset()
empty()
POST
GET
If Statements
If Else Statements
Elseif Statements
Switch Statements
For Loops
While Loops
Do While Loops
Foreach Loops
File Create
File Open
File Read
File Write
File Delete
fgets()
file_get_contents()
Date & Time
$_SERVER
Sessions
Cookies
Arrays

HOW TO USE while LOOPS IN PHP

A while loop repeats a certain block of code as long as a certain condition is true. As soon as it is not, it stops repeating that block of code.

You simply set a certain condition and this is tested at the top of the loop. The general format is:

while(certain condition)

{

execute this code;

}

Example:

$price = 5;

while ($price <= 10 )

{

echo "Still cheap";

$price++;

}

We set our variable $price with a start value of 5. We test to see if $price is less than or equal to 10. If it is, we echo Still cheap and the $price++ increments the $price by 1 (ie. $price + 1 making $price now 6). The loop then checks if $price is less than or equal to 10. If it is (it is in this case as $price is now 6) we echo Still cheap and the $price++ increments the $price by 1 (ie. $price + 1 making $price now 7).

This loop continues until $price is less than or equal to 10. Meaning, if it is 11, then the loop stops executing the code {between braces}.

Home | Privacy Policy | Terms Of Use | Contact Us | Work At Home | Online Jobs | Smart Info | Online Jobs | Data Entry Jobs | Paid Surveys | Info | Info | Typing Jobs | Article Archive | Forum Posting Jobs