The basic PHP syntax is important. After learning this, my teacher said that the most important thing in PHP is the array, which can be seen everywhere. as programming increases, I feel more and more like this.
The basic PHP syntax is important. After understanding this, my teacher said that the most important thing in PHP is the array, which is everywhere. as programming increases, I feel more and more like this.
1. array definition
Array: a collection of data. it organizes a series of data to form an operable whole. It includes elements and subscripts. An element is an element that can store multiple values in an array. each value is called an array element. a subscript means that each element of an array has a related index, which can be regarded as the identification name of the data content in the array, it is also called an array subscript or a key name.
2. array classification
Basically, there are enumeration (index) arrays and associated arrays, which are divided based on the index value type. According to the array dimension, it can be divided into one-dimensional array, two-dimensional array, multi-dimensional array. Commonly used are one-dimensional arrays and two-dimensional arrays. Code:
// Declare an enumerated array
$ Meiju_arr = array ("pig", "www.wozhutou.com", "E-Commerce", "male", "Web engineer ");
Print_r ($ suoyin_arr); // use print_r to print the structure information of the array.
// Declare the joined array below
$ Guanlian_arr = array (
"Username" => "pig head ",
"Web" => "www.wozhutou.com ",
"Hangye" => "e-commerce ",
"Sex" => "male ",
"Position" => "Web engineer"
);
Print_r ($ guanlian_arr); // use print_r to print the structure information of the array.
The associated array and enumeration array are better recognized. the default identifier is enumeration, and the custom identifier is Association.
// The above is a one-dimensional array, and the following is a two-dimensional enumeration array
$ Erwei_arr = array (
Array ("pig", "www.wozhutou.com", "E-Commerce", "male", "Web engineer "),
Array ("pig blog", "wozhutou.com", "e-commerce operation platform", "male", "Web engineer "),
);
// The following two-dimensional joined array
$ Erwei_arr = array (
"A" => array ("pig", "www.wozhutou.com", "E-Commerce", "male", "Web engineer "),
"B" => array ("**", "**********", "e-commerce operation platform", "male ", "Web engineer "),
);
3. create and initialize arrays
Create two types of arrays: 1. use the array () function to declare arrays; 2. assign values to array elements directly.
The code for declaring the second point of the array using the array () function has been used. let's look at the code for directly assigning values:
$ My_arr ["username"] = "anzai ";
$ My_arr ["realname"] = "Anzi ";
$ My_arr ["sex"] = "male ";
$ My_arr ["age"] = "22 ″;
$ My_arr ["position"] = "Web engineer ";
4. access the array
We generally use subscript to access the value of the corresponding element or assign values to the corresponding element (especially when the above value is assigned, the array element is assigned with the symbol "=> "). The access code is directly written here and accessed according to the above value assignment code:
Echo"Industry: ". $ Meiju_arr [2]; // This is the access enumeration array. The value of the array element whose index is 2 is output and the result is e-commerce.
Echo"Industry: ". $ Meiju_arr [hangye]; // This is the access link array. The output index is the value of the array element of hangye, and the result is e-commerce.
Write it here. Sleeping...