indiWiz.com
SiteSearch:
Jump:

Site Map | WizTools.org | jCraze Blog
Web Developer's Den!
Home : WDD : ServerSide
This Article...
Print Version
Add Comment
View Comments
ServerSide
Apache on Linux
Apache User Directory Configuration
PostgreSQL Configuration
CGI: What and How?
PHP Jump Start Guide
Arrays in PHP
PHP and HTML Forms
Variable Passing in PHP
PHP 'include'
Drop-down Menu Navigation in PHP
Edit Your Site Online Using PHP
PHP MySQL Polling System
Dynamic, Search Engine Friendly Pages
Quot Ticker Using SSI
Regular Expressions Reference
PHP File Browser
PHP DB Deletion/Approval Script
Sections

Commniquè
Sign Guestbook!
Read Guestbook!
MailMe!

Subhash's Guide: PHP Arrays

To remind you of the basics, in PHP you need not initialize (declare) a variable. Array is a collection of data items (variables) with a common name but with different subscript (index) value.

In the following ways, array elements can be assigned values:

Type I

Eg.

$bros[0]='Subhash';
$bros[1]='Sarat';

Another element can be inserted into this array:

$bros[]='Sudhir';

This is same as:

$bros[2]='Sudhir';

The PHP interpretor automatically appends the unindexed array assignment next to the last element of the array.

Type II

You can also use the array() method for assigning values to array elements:

$bros=array('Subhash','Sarat','Sudhir');

A Special Type of Array

Traditional languages like C take only integer or integer variable as array subscript. But PHP also takes string as subscript:

$hollywood['handsomehunk']='Arnold';
$hollywood['sexbomb']='SharonStone';

Using array() method:

$hollywood=array('handsomehunk'=>'Arnold','sexbomb'=>'SharonStone');

Multidimensional Array

Yes, PHP also supports multidimensional array:

$hollywood['handsomehunk']['favorite1']='Arnold';
$hollywood['handsomehunk']['favorite2']='Stallone';
$hollywood['sexbomb']['favorite1']='SharonStone';
$hollywood['sexbomb']['favorite2']='DrewBarrymore';


User Comments

Add Comment

[Quick Stats: Number of main threads: 0, Number of sub-threads: 0]

Sign Guestbook | Who is Subhash?
The contents of this site are copyright© 2000-2008, indiWiz.com. All Rights Reserved.