Left Quote    A clever person solves a problem. A wise person avoids it.
- Einstein    
Right Quote
[login] | [Register]

Introduction to PHP

by: Jester
Page: 3 of 7
(View All)

In this section we’ll look at arrays, how we use them, why we use them and we’ll take a look at a few special arrays available to you in PHP scripts.


Arrays in PHP are just what they say, arrays of variables. Let’s take a look at what one would look like.

An array is accessed by the name of the array, followed by square brackets containing the key of the array item we want to access.


An array contains an array of values, each of which are referenced by this “key”. We use the keys to access each individual item within the array. We would assign an array like this:

All that information would be stuck into the $array array. We could then access each item:

The key index consists of numbers, the first value in the array is accessed with 0, NOT 1. The second accessed by 1, the third by 2, and so forth.

Associative Arrays

You don’t have to access array items with number values starting at 0, you can define your own keys.

That may look a bit daunting, but just look at it. Each array key => item is defined separated by commas. The part before the => is the key and the part after it is the value associated with that key.

Associative arrays allow you to associate different words with each array item, it is easier to remember which word accesses what item in large array, your mind rememebrs words easier than having to count, starting from zero, in your head.

Remember the single quotes/double quotes thing? This applies when accessing array items with keys also. An integer value or a variable needs not be quoted, a string value needs aingle quotes, a string value containing a variable needs double quotes.

Special Arrays


This array contains lots of values for you to use in your scripts. It contains the client’s IP address, the browser version, the URI of the script being access, various HTTP headers and much more, here are some examples.


This array contains anything that has been submitted through the POST method. We will be looking at this in the next chapter.


This array contains anything that has been submitted through the GET method. We will be looking at this in the next chapter.


Contains cookie information for the client. Say you set a cookie on their machine named “mycookie” with a value of “Jester”. $_COOKIE['mycookie'] would contain 'Jester'.


This associative array consists of everything in $_POST, $_GET, $_COOKIE and $_FILE.

For more information see The PHP Manual.

In the next chapter we’ll discuss using forms with PHP scripts and how we process the information submitted.

1  |  2  |  3  |  4  |  5  |  6  |  7  |  
Next »

No Comments for this page.

You Must be logged in or a member to comment.

Tutorial Stats

Tutorial Stats

9 Total Comments
5 Rating of 5 (3 Votes)


Tutorial Options

· Login to Rate This Article
· Login to Post a Comment
· Read more by this author
Digg This Article! Bookmark This Article Reddit: Bookmark This Article BlinkList: Blink This Article! YahooMyWeb BlogMarks: Add This Mark! Furl: Save This Article Spurl: Mark This Article



· Simple PHP Tutorial
· One File Website
· Pagination with PHP
· Building a Comments Script
· Complete Members System
· Variable Scope

"" Copyright © 2002-2021; All rights lefted, all lefts righted.
Privacy Policy