An array is a collection of data. it organizes a series of data to form an operable whole. Arrays can contain a lot of data, such as scalar arrays, arrays, objects, resources, and other syntax structures supported by PHP. This chapter describes the two types of compound data in PHP.
Array
What is array)
An array is a collection of data. it organizes a series of data to form an operable whole. Arrays can contain a lot of data, such as scalar arrays, arrays, objects, resources, and other syntax structures supported by PHP.
Each data in an array is called an element. the element consists of an index (key name) and a value. The index of an element can be composed of digits or strings. The value of an element can be of multiple data types, the syntax format for defining arrays is as follows:
You can use the array () language structure to create an array. Each array element is separated by commas (,).
$array=('value1','value2'......)
Or
$array[key]='value'
Or
$array=array(key1=>value1,key2=>value2......)
Parameters:
The parameter key is the subscript of the array element, and the value is the element corresponding to the array subscript.
You can use the short array definition syntax from 5.4 and replace array () ().
The previously defined array is like this.
"bar", "bar" => "foo",);
// From PHP 5.4
$array = [ "foo" => "bar", "bar" => "foo",];?>
Array definition example
The following are all in the correct format.
'Php', 1 => 'Chinese net'); $ arr3 [0] = 'tmpname';?>
After an array, the number of elements in the array can be changed. as long as an array is assigned a value, the length of the array is automatically increased. For more information about arrays, see The php Array (Array) topic.
In the next section, we will explain the "object" of the two composite data types in PHP"
The above is php: detailed description of the array (array) data type instance. For more information, see other related articles in the first PHP community!