Professional Documents
Culture Documents
Arrays in PHP Are A Type of Data Structure, Which Allows Us To Saves
Arrays in PHP Are A Type of Data Structure, Which Allows Us To Saves
different variable in order to store multiple elements with a similar data type under a single
variable. The arrays help to create a list of similar elements, accessible by index or key. The array
is used here to store each element in one variable and also to enable easy access via an index or
a key. Using a function in PHP, an array is generated. Now we will try to understand arrays in PHP
using the syntax and examples. PHP arrays are implemented by the use of array function which
is written as “array()”. It has a very simple syntax that makes the usage of the array very easy.
Below is the syntax to declare and initialize the array in PHP.
array_name = array("value1", "value2", "value3",..)
2. Multi-dimensional array
● A multi-dimensional array may be defined as the kind of array that allows us to assign
values in multiple arrays at the same time.
● The values assigned to the multi-dimensional array could be heterogeneous that means
values of different data types could be stored in the arrays and it has to be taken care that
the sequence of items of specific data types should be same in all the arrays.
● Here we will look on two-dimensional array syntax. Well, just for your information, the
complexity of array increases as the dimension of the array increases.
$array_name = array
(
array("String1", "Int1", "Int11"),
array("Stirng2", "Int2", "int22"),
array("String3", "Int3", "int33"),
array("String4", "Int4", "int44"),
)
Advantages
1. Multiple values under one name
2. Endorse data structure implementation
5. Less memory utilization
Easy to rember