Array
Array
- Array is the linear collection group of multiple of data.
- In PHP there are only dynamic array not static
An array is a variable that stores a set or sequence of value.Such as text or numbers,or another array.An array containing other array is known as a multidimensional array.
Algorithm for creating an array
1. First take a array variable name and ensure $ sign before taking variable name.
2. Take 3rd bracket [] after variable name
3.Take equal sign
4.Arrange array value if you need string value then you assign string value into double quotation
Code is here -
<?php
$arrayVariableName=array();
$arrayVariableName[0]="I love Web New Idea Concept";
echo $arrayVariableName[0];
?>
Output
I love Web New Idea Concept
Explanation:
In above example $arrayVariableName is an array, initially it does not contain any elements. $arrayVariableName= "I love Web New Idea Concept", adds one element into the array whic is stored at zero index by default. You can retrieve particular element from arrays by specifying its index.In this example an array contain only one element which is stored at zero index.
Numerically indexed Arrays
Stored and access in linear fashion. In php, the indices start at zero by default, although you can alter this value.
<?php
$books = array("Programming","History","Story","Literature");
foreach($books as $booksAarayIndexing=>$var){
echo $booksAarayIndexing."=>".$var."<br/>";
}
?>
This code creates an array called $books containing the four values given "Programming","History","Story","Literature"
***NB Like echo, array() is actually a language construct rather than a function.