In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "how to use the type of PHP array". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use the type of PHP array.
In the previous article, we brought you "how to use the switch statement in PHP (instance parsing)". This article introduces the basic content and example explanation of PHP's switch statement in detail. Today, let's continue to take a look at the array of one of the most important data types in PHP. I hope it will be helpful to everyone!
PHP array
What is an array?
Array is one of the most important data types in PHP, which is widely used in PHP. An array can store many different types of data and is a compound data type. An array is a special variable that can store multiple values in a single variable.
In order to achieve the purpose of batch data processing in a collection unit, we need to use arrays to organize multiple interrelated data together to form a collection.
How do I create an array?
In PHP, the array () function is used to create an array, with each array element separated by a comma, as an example:
In the above example, we added string, integer, Boolean, floating-point type to the array. There are a lot of elements in an array, and to find it, we need to use two concepts: "key (subscript)" and "value". You can get the corresponding array elements by key values.
The subscript, the key, usually starts at 0, 0.1.2.3. That is,
Output result:
The subscript usually starts at 0, so can we not start from scratch? Then one of the types of arrays is called indexed arrays.
Indexed array
The subscript of an indexed array, that is, the key name, is made up of numbers. Generally speaking, the default starts from 0, and each number corresponds to the position of an array element in the array. PHP automatically assigns an integer value to the key name of the indexed array, and then automatically increments from this value. As follows:
0 = > "study hard"; it means: the subscript of good study is 0, "every day up" after "good study", its subscript is automatically increased by 2.
Where = > is a symbol, which is called the key-value correspondence. It can be understood as a subscript that declares this value.
Therefore, the subscript of "Happiness is like the East China Sea" is declared to be 5, and the subscript of "Life beyond Nanshan" increases progressively after 5 to 6.
Examples are as follows:
Output result:
From the above example, we can summarize the rules of indexed arrays:
If the indexed array does not force its subscript to be declared, its subscript starts at 0.
The specified subscript his subscript is the value specified by me.
A value that forces the subscript to be specified. The value after it, if no subscript is specified. Their subscript is incremented by + 1.
Associative array
The subscript of an associative array is 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. Examples are as follows:
Output result:
The subscript of an associative array can be an integer or a string. If the subscript is a string, enclose the subscript in single or double quotation marks.
At this point, I believe you have a better understanding of "how to use the types of PHP arrays". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.