PHP Array

PHP Array

Array is a type of structured data that is useful to store some of the same type of data. Parts that make up the array called array elements, each element can be accessed separately through the array index.

One-Dimensional Array
$country[0] = "England";
$country[1] = "France";
$country[2] = "United States";
$country[3] = "Japan";

print ("I live in $country [2]");
The above code when run on a browser, will appear the words:
I live in France.

Array index starts from 0. So the array index 0 declare the first element of the array, the array index 1 states the second array element, and so on.

Multidimensional Arrays
Included in this data type is an integer (not use commas.) For example:

$fruits= array (
     "apple" => array(
        "color" => "red",
        "taste" => "sweet"
     "banana" => array(
        "color" => "yellow",
        "taste" => "sweet"

print ("The color of the apple is");
print ($fruits ["apple"] ["color"])."< br>";
print ("The taste of banana is");
print ($ fruits [“banana”] [“taste”]);

The above code will result :
The color of apple is red
The flavor banana is sweet


Post a Comment