spacer
Web Development Tutorials PHP Tutorials
 Developer Newsletter

Tutorials
AJAX
ASP
CGI & Perl
CSS
Flash
HTML
Illustrator
Java
JavaScript
Linux
MySQL
PHP
Photoshop
Python
Wireless
XML
Miscellaneous


Scripts Directory
AJAX Scripts
ASP Scripts
ASP.NET Scripts
CGI & Perl Scripts
Flash Scripts
Java Scripts
JavaScript Scripts
PHP Scripts
Python Scripts
Remotely Hosted Scripts
Tools & Utilities Scripts
XML Scripts

Web Hosting Directory
ASP.NET
Budget
Dedicated Servers
Ecommerce
Linux
Resellers
Shared
Small Business
Windows

Developer Manuals
Learn HTML
Learn PHP
Learn CSS
Learn AJAX
Learn JavaScript
Learn Pear
Free White Papers

Developer Resources
Developer Tools
Developer Content
Survey Software
Dedicated Servers




Introduction to PHP Programming

By PHP Catalyst
2007-11-19


Types of Arrays in PHP

In PHP, there are two types of Arrays. One is Numerical or Indexed Array and the Associative Array.

In Numerical or an Indexed Array, the indexer of the array which is used to determine the position (also known as Key) of the stored data element is an integer which begins at zero. Consider this example:

Position in Array Name
0 =>TCP
1 =>IP
2 =>DNS
3 =>HTTP
4 =>FTP
5 =>SMTP

In the left column, we are displaying the position of the name of the protocol that is on the right hand side. The position is an integer and is starting at zero. So, if you were to retrieve the name of the protocol which is at 4th position, then the Array will return 'FTP' and not 'HTTP'. In this way PHP uses integers as indexers or the key to store and determine the position of the data element in the Array. So how is it different from an Associative array?

In Associative array, the key or the indexer of the array which is used to refer to the data element is a string and not an integer. Consider this example:

Abbreviation Expanded Term
TCP =>Transmission Control Protocol
IP =>Internet Protocol
DNS =>Dynamic Naming System
HTTP =>Hyper Text Transfer Protocol
FTP =>File Transfer Protocol
SMTP =>Simple Mail Transfer Protocol

In the above example as you can see, we have used strings and not integers to determine the position of the data elements. So, if we query the array for the data element which is stored at the position of 'SMTP' (our key for the data element), the array will return 'Simple Mail Transfer Protocol'.

To summarize, Indexed arrays have integers as their key values while Associative arrays have strings as their keys. Let's move on to our next topic Creating arrays in PHP.

Tutorial Pages:
» What can I do with PHP?
» Popoular Features of PHP
» Basics of PHP
» Variables in PHP
» Data Types in PHP
» Expressions and Operators
» Control Structures in PHP
» Functions in PHP
» Declaring Functions in PHP
» Scope of a Variable
» Built-in Functions in PHP
» Handling Strings in PHP
» Printing Strings in PHP
» String Comparisons in PHP
» Manipulating Strings in PHP
» Arrays in PHP
» Types of Arrays in PHP
» Creating Arrays in PHP
» Array Operations in PHP


 | Bookmark Print |   Write For Us
Related Tutorials:
» Web Database Access from Desktop Applications
» CubeCart 3.0 Installation and Configuration
» PHP Site Search Made Easy
» Installing and Configuring Drupal 6.1
» Desktop Application Development with PHP-GTK
» Installing PHP on Windows



About the NetVisits, Inc Network | Write For Us | Advertise
Copyright ©2007 NetVisits, Inc Network. All Rights Reserved. Privacy Policy.
Visit other NetVisits, Inc. sites: