PHP array type-associated array

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.