HTML
HTML
<head>
<title>
</title>
</head>
<body>
<?php
?>
</body>
</html>
simpleFor2.php
<html>
<head>
<title>
For Loop
</title>
</head>
<body>
<h1>for loop</h1>
<?php
$brush_price = 5;
echo "<tr><th>Quantity</th>";
echo "<th>Price</th></tr>";
echo "<tr><td>";
echo $counter;
echo "</td><td>";
echo "</td></tr>";
echo "</table>";
?>
</body>
</html>
syntax
while(contition true)
{code to execute;
while.php
<html>
<head>
<title>
</title>
</head>
<body>
<?php
$i = 1;
$i++;
} // end while
?>
PHP Arrays:
An array is a data structure that stores one or more values in a single variable. For experienced programmers it is
important to note that PHP's arrays are actually maps (each key is mapped to a value).
A Numerically Indexed Array
If this is your first time seeing an array, then you may not quite understand the concept of an array. Imagine that you
own a business and you want to store the names of all your employees in a PHP variable. How would you go about this?
It wouldn't make much sense to have to store each name in its own variable. Instead, it would be nice to store all the
employee names inside of a single variable. This can be done, and we show you how below.
PHP Code:
$employee_array[0] = "Bob";
$employee_array[1] = "Sally";
$employee_array[2] = "Charlie";
$employee_array[3] = "Clare";
In the above example we made use of the key / value structure of an array. The keys were the numbers we specified in
the array and the values were the names of the employees. Each key of an array represents a value that we can
manipulate and reference. The general form for setting the key of an array equal to a value is:
$array[key] = value;
If we wanted to reference the values that we stored into our array, the following PHP code would get the job done.
PHP Code:
Display:
Arrays consisting solely of atomic entities are referred to as being single-dimensional. Multidimensional arrays consist of
other arrays. For example, you could use a multidimensional array to store U.S. state information. Using PHP syntax, it
might look like this:
$states = array ("Ohio" => array ("population" => "11,353,140", "capital" => "Columbus"),
$states["Ohio"]["population"]
This would return the following value:
11,353,140
</body>
</html>
<html>
<head>
<title>
Basic Array
</title>
</head>
<body>
<h1>Basic Array</h1>
<?php
$camelPop[1] = "Somalia";
$camelPop[2] = "Sudan";
$camelPop[3] = "Mauritania";
$camelPop[4] = "Pakistan";
$camelPop[5] = "India";
?>
</body>
</html>