Array in PHP

An array is a special variable or multiple data container object. Unlike a variable holding just one value, an array can hold multiple values in a single type array container. All elements in an array have numeric index which is used to access their element value.

first indexsecondthirdfourthfifthsixthseventhlast index
01234567indices/keys
“zero”“one”“two”“three”“four”“five”“six”“seven”elements/values
Eg

 <?php $arrayBox = array( 0 => “zero”, one => “1”, keys => “values” ); ?>

Allocate memory for the elements in the array variable:

 <?php echo $arrayBox[1]; ?> 

it will print out the value of index 1.

Array of arrays or so called multidimensional array. An array which is, its components are arrays. An element should be accessed by a corresponding number of indexes

Eg

 <?php $arrayBox = array( “person” => array( “married” => array(“Status” => “Yes”, “Children” => “No”) ) ); ?> 

Output:

 <?php echo $arrayBox[“person”][“married”][“Status”];?>

Here we have declared and assigned the multidimensional array type in order to access its corresponding values as an index value.