Basics of PHP

Written By: Ryan “boxdain” Macy

- 19 May 2006 -

Description: This intro to PHP covers syntax, variables, operators, condition statements, and an intro to arrays.

  1. Basic Syntax
  2. Variables and Operators
  3. Condition Statements
  4. Arrays

Arrays

Arrays in PHP are variables that store a collection of data . Each variable key is mapped to a value. So let's say you have a joke machine and you want a fast easy way to store each joke, you could use arrays for this job!

Here is the basic syntax:

$array_name[key] = value
 
// and
 
$array_name = array( key=>value)

Now the key is a number that determines the possition of a value within an array. But remember this, PHP starts counting from 0, so the first value would be $array_name[0]. Got it? You can also put arrays in arrays like below:

$array_name = array(
0=>; Array( 0=>"See it works!"
)
);
 
print $array_name[0][0];

You should get

See it works!

Well that's arrays in a nutshell. Now when you see them in code you will know what they do.

FIN

Well we have gone over most of the basics of PHP. I have skipped over a few things in order to keep it simple and manageable for beginners. Make sure you guys check for my next article as we get into loops and more complicated PHP functions.

<< Previous