Php Arrays

An array is a special variable, which can hold more than one value at a time. For example if you want to store 100 numbers then instead of defining 100 variables its easy to define an array of 100 length.

Numeric Array

These arrays can store numbers, strings and any object but their index will be represented by numbers. By default array index starts from zero.

Example :-

Result

Value is 1
Value is 2
Value is 3
Value is 4
Value is 5
value is one
Value is two
Value is Three
Value is four
Value is five

Associative Arrays

This array is used to store the value in the form of key and value pair. Key is keyword as a index for element . The associative arrays are very similar to numeric arrays in term of functionality but they are different in terms of their index. Associative array will have their index as string so that you can establish a strong association between key and values.

Example :-

Result

Salary of mohammad is 2000
Salary of qadir is 1000
Salary of zara is 500
Salary of mohammad is high
Salary of qadir is medium
Salary of zara is low

Multidimensional Arrays

When ever an array contains more than one array inside the same array then it is called a multidimensional array. A multi-dimensional array each element in the main array can also be an array. Values in the multi-dimensional array are accessed using multiple index.

Example :-

Result

Marks for mohammad in physics : 35
Marks for qadir in maths : 32
Marks for zara in chemistry : 39