Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the components of the php array

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "which parts of the php array". In the daily operation, I believe many people have doubts about which parts of the php array. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what parts of the php array are composed of?" Next, please follow the editor to study!

Php array of three components: 1, "array name", an array is an ordered sequence of variables, if a limited number of variables of the same type of set naming, then the name for the array name; 2, "value", that is, the array stored elements; 3, "key", each element by a special identifier to distinguish, this identifier is called key (also known as subscript).

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

The php array consists of three parts: array name, value, and key.

Example:

In the above example: $array is the array name, the value before "= >" (0, 1, 2, 3...) is the key (subscript), and the value after "= >" (1, 2, 3.) is the value.

1. Array name

An Array is an ordered sequence of elements. If you name a limited collection of variables of the same type, the name is the array name.

Array names follow certain rules (the same as variable names):

It must start with a $sign, followed by the name of the variable. $is not part of the variable name.

Must start with a letter or an underscore

Cannot start with a number

Can only contain letters (Abeliz), numbers (0,9), and underscores (_)

Unlike other languages, some keywords in PHP can also be used as variable names (for example, $true, $for).

Note: variable names in PHP are case-sensitive, so $var and $Var represent two different variables.

2. Key name and key value

The array array is an ordered set of variables, where each value is called an element. Each element is distinguished by a special identifier called a key (also known as a subscript).

In PHP, key names can be divided into two types:

Pure number

A string or a mixture of strings and numbers

An indexed array with a number as the key name, and an associative array with a string or a mixture of strings and numbers as the key name.

1) indexed array

The subscript (key name) of an indexed array consists of numbers. By default, starting from 0, each number corresponds to the position of an array element in the array, which does not need to be specified. PHP automatically assigns an integer value to the key name of the indexed array, and then increments automatically from this value.

For example, the example given at the beginning is an indexed array.

2) associative array

The subscript (key name) of an associative array consists of a mixture of numeric values and strings, and if an array has a key name that is not a number, then the array is an associative array.

If the key name is a string, wrap the key name with a delimiter-single quotation mark''or double quotation mark "".

At this point, the study of "which parts of the php array are made up" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report