PHP Programing language

adplus-dvertising
What is An Array
Previous Home Next

What is An Array

In PHP An array is a way of holding multiple closely-related values, such as the test scores of all students in a class. An array is made up of a key and a value, and the key points to the value. The Syntax using in Array

array array ( [mixed ...] ).

In PHP the Array is two types:

Indexed Array:

In indexed array the array is represented  the keys are numeric and starts with 0, and the values can be any data type. The following shows two ways of assigning values to an indexed array.

Example:

$fruit=array ("Apple","Orange","Bananan");

The second way to assigning the value is:

$fruit[0]="Apple"; 
$fruit[1]="Orange"; 
$fruit[3]="Banana";

Associative Array:

In an associative array, the keys are not necessarily numeric, and even when they are numeric, not necessarily in any order. So, when you are putting data into an associative array, you'll need to make sure you specify both the key and the value.

Example:

$Book Price=array ("math"=>100,"science"=>50,"Hindi"=>75);

the second way to represent An Array:

$Book Price ["math"] = 100; 
$Book Price ["science"] = 50; 
$Book Price ["Hindi"] = 75;

Multidimensional Array:

The arrays in the examples above are 1-dimensional. However, there will be times when multidimensional arrays are desired. What's a multidimensional array? That's when you have arrays of arrays.

Example:

$array1 = array (100,150,120);
$array2 = array (90,115,180);
$array3 = array (200,215,220);
$big_array = array ($array1, $array2, $array3);

$big_array is now a 2-dimensional array.
print {$big_array[1,2]};
Previous Home Next