Home Tutorial Php Phpbasics Introduction to PHP Array

 
 

Share on Google+Share on Google+
Introduction to PHP Array
Posted on: October 14, 2009 at 12:00 AM
Advertisement
Introduction to PHP Array, this tutorial covers up the introduction with a simple example on array, the explanation of the program will help you to understand the concept of PHP program in a better way.

What is Array?

An array in PHP is actually an ordered map, what is a map? A map is a type that associates values to the keys, you can consider as list, stack, hash table, dictionary or an array. An array can be created with the help of array() language construct. It takes number of parameters in the form of key=>value pair separated by comma.

General format of an array is:

array( key=>value)

An example of an array is given below:

<?php

$first=array('Name' =>'Rose', 18=>"true");

echo $first['Name']."<br/>";

echo $first[18];

?>

Output of the above example is:

Rose
true

 In above example

  • <?php ?> is the delimiter, which is mandatory for any PHP program.

  • $first is the name of the variable

  • array() is the language construct

  • 'Name' and 18 are the keys, here character type keys should be enclosed within single or double quote and these are case sensitive, if  you declare a key as 'Name' and if you write 'name' to access that key then an error message will be generated,

  •  echo is the language construct

  • $first['Name'] is the actual way to access the array.

  •  ' . ' operator is used to concatenate  strings.

  • <br/> is used to break line

  • Each line should be ended with a semicolon but at the last line it is optional.

A key may be either an integer or string, floats in the key are truncated to integer.

 

 

 

Advertisement

Related Tags for Introduction to PHP Array:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 14, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com