PHP: Types of Arrays

Arrays are means of storing related data (a collection of variables) in programming languages. This article on Java arrays gives a good and simple introduction to arrays. Yeah! It’s a different programming language from PHP but the concept of arrays is the same across different programming languages (the code snippets below are of the PHP language).

Numeric Arrays

They use numbers as access keys i.e.

$variable_name = array(n=>value,...);

$fruits = array(0=>'Apple',

Associative Arrays

They use descriptive names for id keys i.e.

$variable_name = array('key_name'=>value);


Multidimensional Arrays

These are arrays that contain nested arrays. They allow programmers to group related data. A good usage of this in real world software is the creation of Drupal custom forms especially in pre-processor functions that are found within the template.php or .module files.

$movies = array(
'comedy'=>array('Pink Panther','Big Momma'),
'action'=>array('Die Hard','Expendables'),
'epic'=>array('The Lord of the Rings'),
'Romance'=>array('Romeo and Juliet')
Please follow and like us:

Leave a Reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see

August 1, 2014

Posted In: Information Technology

Tags: ,

Leave a Comment