In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.