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 introduces the relevant knowledge of "introduction to the basic operation of PHP array". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The concept of array
Array is a very important concept in PHP. We can think of an array as a collection of similar data. In fact, an array is an ordered graph.
PHP also provides more than 70 built-in functions to manipulate arrays.
Create an array
Create an array using the array () language structure:
You can also use the array controller [] to create an array:
Array key name and value
The array entity contains two items: the key name and the value.
In the following example of creating an array:
$arr_age1 = array (18, 20, 25); we assigned $arr_age1 three array units (also known as elements) with values of 18, 20, and 25, respectively. The system automatically assigns three numeric sequence numbers to the three array units, which are 0, 1, and 2, respectively. That is, the complete structure of the $arr_age1 array is:
Array ([0] = > 18 [1] = > 20 [2] = > 25) the sequence number assigned by this system is called the key name, and the array with the key name ID is called the indexed array (indexed array).
Of course, you can also specify the key name manually:
$arr_age1 = array (0 = > 18,1 = > 20,2 = > 25)
Note: manually specifying the key name can not start with 0 or specify the key name in numerical order. When a new cell is added to the array without specifying a health name, the system automatically adds 1 to the largest numeric key in the existing array as the key name of the new unit.
When using a string instead of a numeric index as the key name, such an array is called an associative array (associative array):
$arr_age2 = array ("wang" = > 18, "li" = > 20, "zhang" = > 25); but in PHP, there is no clear boundary between the two arrays, and the two can be mixed. Note that the associative array is sensitive to the case of key names.
Output array cell values
You can access the output array cell values in the following ways:
Echo $arr_age1 [0]
/ / output: 18
Echo $arr_age2 ["wang"]
/ / output: 18 in some cases, for debugging, you may need to output the data and structure of the entire array. In this case, you need to use the print_r () or var_dump () function, as shown in PHP print_r and var_dump output arrays.
Operand array unit
You can manipulate array units like ordinary variables, such as:
The $arr_age2 is now:
Array ([wang] = > 28 [li] = > 20 [zhang] = > 25)
To check that an array unit is set, use isset ().
Destroy array
Use the unset () function to destroy an array unit or an entire array:
Multidimensional array
If the values in an array are also arrays, we call such an array a recursive array or a multidimensional array.
Example:
This is the end of the introduction to the basic Operation of PHP Array. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.