In this array the index associated with each element is incremental numbers starting from 0.
echo $my_data[2] // mydata3
Creating and displaying Array
Associative Array
We can create an array with assigned Key ( indices ) and values like this. Note the use of => operator to associate key with its value.
$var=array(013=>"RKt",005=>"Bin",007=>"Alen");// Array key with value
$ar=array("FName"=>"John","Address"=>"Streen No 11 ",
"City"=>"Rain Town","Country"=>"USA");
We can create an array by breaking string. Let us try with some simple examples.
///Storing the sample paragraph in a variable /////
$string='plus2net provides easy tutorials for learning web programming';
$new_array=explode(" ",$string); // create an array by breaking string
// Let us display all elements of the array. ///
while (list ($key, $val) = each ($new_array)) {
echo "$key -> $val <br>";
}
Here we have used space as delimiter and created the array by breaking the string.
The output of above code is here.
Now let us try another program. This is a keyword list, we will try to create array by breaking the string with coma as delimiter. Only changes to above code is shown here