Saturday, 5 May 2012

Arrays

Array:


An array is a list of same kind of element.
In PHP array starts from
Single dimensional Index array:
This is the integer subscript which denotes the position of the requested value.
syntax:
$name[Index1];

Example: 



<?
$meat[0] = "chicken";
$meat[1] = "steak";
$meat[2] = "turkey";
print $meat[2];
?>

out put:
turkey

For 3 varieties we have created array in this manner but if there are thousands then what to do. Then we need to use array function.


Array function syntax:
$name=array(Index1,Index2,Index3...Indexn)

Example:
$meat=array("chicken","turkey","steak");

Another manner of assigning values
$meat[]="chicken"
$meat[]="turkey"
$meat[]="steak"

Multidimensional Indexed Array:
Syntax:
$name[Index1][index2][Index3]..[IndexN];

An element of dimensional Indexed array:
$position=$chess_board[5][4];









No comments:

Post a Comment