Amazon.com: PC Books || Educational Software || Magazines
Amazon: Books-CA || Software-CA || Books-UK || Software-UK

HTML | Javascript | ASP | PHP | VBScript | SQL | Hardware | PC FAQ| WinXP|

Learn to Build, Upgrade, or Repair your Computer Ebook + PC Safety 101 kwwebservice.com Reasonably priced web development & hosting
PHP Basics
Introduction
Variables & Arrays
Sub & Functions
If Statements
Case Statements
Loop Statements
Date Objects
Form Processing
Text File Objects
Database Access
Adding Record
Updating Record
Deleting Record
Virtual Includes
Cookies
Session
Server Variables
Creating Login Page
E-mail
PHP Books @
CA Amazon
UK Amazon
US Amazon

  :: Home
PC Topics
  :: Build A PC
  :: Windows XP
  :: PC Help
Tutorials
  :: HTML
  :: JavaScript
  :: ASP
  :: PHP
  :: VBScript
  :: SQL
Miscellaneous
  :: Code/Scripts
  :: Forum
  :: Links
  :: Contact us
  :: Tell A Friend
  :: In Somali
  ::
Web Articles
  Top Web Hosting
Reviews
  Processing
Online Card Payment Guide
  Domain name
registration & buying guide
  Getting
a website online guide
  Search Engine
submission & optimization tips
Netfirms Web Hosting
Free trial
Quality business correspondence.
Yahoo! Search Marketing


PHP Variable

PHP variables are declared using using dollar sign $.  For example, you can declare empty string variable this way: $varaibleName=""; or variable with text this way; $welcome="Hello Visitor. Welcome to my website.";.
Watch this program to see how variables are used:
<?php
   $name="John Doe";
    $email="johnd@pctalknet.com";
   $age=356;
    print"Your Name: $name <br>";
    print"Your Email: $email<br>";
    print"Your age: $age";
?>

The following is the result from the above example:
Your Name: John Doe
Your Email: johnd@pctalknet.com
Your age: 356

PHP Arrays

An array is an indexed list of things called elements or group of related variables. For example, say that we want declare variables for list of cars like this;
$car1="";
$car2="";
$car3="";
...

Here is how you would declare list of cars using array:
Dim cars(3); We simply declared array that takes 4 items.  To assign values to this array, do these:
$cars(0)="Jeep Grand Cherokee"
$cars(1)="Jeep Wrangler"
$cars(2)="Jeep Liberty"
$cars(3)="Jeep Cherokee Briarwood"

Use this statement to write an item in the array: echo"$cars(2)"; This will write the 3th car on the list.
Bellow is the example we did in code
ExampleExplanation
<?php
$cars[0]="Jeep Grand Cherokee";
$cars[1]="Jeep Wrangler";
$cars[2]="Jeep Liberty";
$cars[3]="Jeep Cherokee Briarwood";
echo"$cars[0], ";
echo"$cars[1], ";
echo"$cars[2], ";
echo"$cars[3], ";
?>
This is simply illustration, NOT good example.   If you writing items from an array, you would probably write all the items at one time using loops instead of listing echo statements.
Result

Jeep Grand Cherokee, Jeep Wrangler, Jeep Liberty, Jeep Cherokee Briarwood,
To write the array using for loop statement, do this.
ExampleExplanation
<?php
$x=0; $cars[0]="Jeep Grand Cherokee";
$cars[1]="Jeep Wrangler";
$cars[2]="Jeep Liberty";
$cars[3]="Jeep Cherokee Briarwood";
while($x < 4)
{
  echo "$cars[$x] <br>";
$x++;
}
?>
The variable x which starts from 0 to 3 acts as an index for the array.
Result
Jeep Grand Cherokee
Jeep Wrangler
Jeep Liberty
Jeep Cherokee Briarwood

Two dimensional Arrays

You can define two or more dimensional arrays by puting numbers withing the parenthesis.  
Here is how you would define two dimensional array $person["John D","123"].  The reason you may use this type of array is when you have records of each item.  For example, car, year, price,... and you want display one record at a time.
The following is an example of two dimensional array:
ExampleExplanation
<?php
$car1[0][1]="Jeep Grand Cherokee";
$car1[0][2]=2002;
$car1[1][1]="Jeep Wrangler";
$car1[1][2]=2002;
$car1[2][1]="Jeep Liberty";
$car1[2][2]=2003;
$car1[3][1]="Jeep Cherokee Briarwood";
$car1[3][2]=2003;
for($x=0; $x<4;$x++)
{
for($i=1; $i<3;$i++)
{
echo $car1[$x][$i]."<br>";
}
}
?>
This array has three cars and each car has two fields or columns.  It's like a table, row 0 has record of one car, row 1 has record of another car and so on  We also define nested for loops.  First one reads the row and second one reads the column.
Result
Jeep Grand Cherokee
2002
Jeep Wrangler
2002
Jeep Liberty
2003
Jeep Cherokee Briarwood
2003
Introduction to PHP Functions
Listed @ ConsumerVote.com - The Consumer Rated Web Directory
PC Articles
  Computer Safety
prevent viruses & Spyware