php Tutorials
Creating An RSS Feed With PHP And MySQL
Retrieving XML With Curl and SimpleXML
Using curl to Query Remote Servers
MySQL Basics
PHP mySQL Voting Booth
File Download Security
PHP Fundamentals

PHP Fundamentals



For loops have three settings initial loop variable, contition to meet, amount to increment loop variable. for ($a=0;$a>=10;$a++) sets $a to 0 then runs through the loop and increments $a before running the loop again until the condition is met.

for ($a=0;$a>=count($array);$a++) {
  echo $array[$a];

Here we threw in count which we'll get in depth with shortly. Count returns the total number of values in the variable $array.


Foreach is almost a for loop for arrays. Foreach takes each variable of an array and outputs it as another variable set in the foreach statement.

foreach ($days $day) {
    echo "$day";

This is for simple arrays. Below is for associative arrays.

$months=array("01" => "January",
foreach ($months as $key => $value) {
    echo "$key - $value";


While loops execute until a certain condition is met. The major difference between this and for loops is that while loops don't adjust the condition variables. While loops are great for use with getting information from mysql queries.

while ($a<=10) {
    echo "$a";
Switch ... Case Flow Control <<  1 2 3 4 5 6  >> Includes and Functions
New Content