In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "the method of declaring arrays in PHP". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "the method of declaring arrays in PHP".
PHP declares an array in the following two ways:
You can declare an array by directly assigning values to array elements
Declare the array using the array () function.
When you declare an array using the above method, the keys and values can be defined by yourself, specifying not only the value of the element, but also the subscript of the element.
First, declare the array by direct assignment
Format:
Array variable name [subscript] = value
Where the subscript (index value) can be a string or an integer, and the subscript needs to be wrapped with [].
Code example:
The running results are as follows:
Array (4) {
[0] = >
String (16) "Zhang San"
[1] = >
String (10) "Li Si"
[2] = >
String (10) "Wang Wu"
[3] = >
String (27) "how many of them are there?"
}
Note: the above way to add data can be added at any time, access to the data is to use the "$array variable name [subscript]" way to obtain data.
If the index value is incremented, we can also not specify a specific index value in square brackets, where the index value increases by default starting at 0.
Code example:
The running results are as follows:
Array
(
[0] = > Zhang San
[1] Li Si
[2] > Wang Wu
[3] = > how many are they?
)
Declare an array using the array () function
Declaring arrays can also be created using the array () function. It accepts a certain number of key= > value parameter pairs separated by commas. The syntax format is as follows:
Array variable name = array (key1 = > value1, key2 = > value2,..., keyN = > valueN)
Code example:
The running results are as follows:
Array (4) {
[0] = >
String (4) "Zhang San"
[1] = >
String (4) "Li Si"
[2] = >
String (4) "Wang Wu"
[3] = >
String (13) "how many people are they?"
}
If you do not specify a subscript using the = > symbol, it defaults to an indexed array. The default index value is also incremented from 0.
Code example:
The running result is the same as above.
At this point, I believe you have a deeper understanding of "the method of declaring arrays in PHP". 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.