PHP Array Data Type With Examples

Array Data type

An array is a variable that can hold more than one value at a time. It is useful to aggregate a series of related items together

An Array is also knwon as compound data-type which can store multiple values of same data type.

An Array can be declared in two way.

  • An array can be declared using the array() function.
  • An array can be declared wrapping with [ and ].


Example:

Result:

array(3) { [0]=> string(3) "Red" [1]=> string(5) "Green" [2]=> string(4) "Blue" }
array(3) { ["Red"]=> string(7) "#ff0000" ["Green"]=> string(7) "#00ff00" ["Blue"]=> string(7) "#0000ff" } 

Read More: