It contains scalar data, which can be selected independently by index values. different from the array, the index value of the associated array is not a negative integer but an arbitrary scalar. These scalar values are called Keys and can be used to retrieve the values in the array later.
PHP array type-associated array
What is a PHP associated array?
In the previous article, we introduced "PHP array type-number index array". today we will introduce associated arrays in detail.
In addition to array index arrays, PHP also has an associated array, which is generally called hash or map in other computer languages.
Using an associated array, we can specify a keyword for each array element, which is called a key)
The example of associating arrays is as follows:
1, "second" => 2, "third" => 3); echo $ newarray ["second"]; $ newarray ["third"] = 8; echo $ newarray ["third"];?>
Output result:
Using while loop to traverse arrays: Indexes and associated arrays
Using foreach loop to traverse: index and associated array
The above is the PHP array type-detailed content of the associated array. For more information, see other related articles in the first PHP community!