Arrayis a form of organizing a number of variables of the same type in an orderly manner, in order to deal with them conveniently. The collection of these ordered, homogeneous data elements is called an array. The following describes the array declarations in PHP.
First, an overview of arrays
1. The nature of arrays: managing and manipulating a set of variables, batch processing
2. Compound type when array (multiple can be stored)
3. You can store any length of data in an array, or you can store any type of data
4. Array can complete the function of other language data structure (list, queue, Stack, collection Class)
Ii. Classification of arrays
There are multiple cells in the array, (cells are called elements)
Each element (subscript [key] and value)
The element is accessed by subscript (key) when the element is accessed by a single
1. One-dimensional arrays, two-dimensional arrays, three-dimensional arrays ... multidimensional arrays (arrays of arrays, where other arrays are stored in the array)
There are two types of arrays in 2.PHP
Indexed array: The index of an ordinal integer that is the subscript
Associative array: Is the subscript is the string as the index
Subscript (integer, string) only these two types of
Three, array of multiple declaration methods
1. Assigning a direct array element to a value declaration
If index subscript is not given, it will be indexed sequentially starting from 0
If index subscript is given, the next will increase by 1 from the largest start
If the preceding subscript appears, the assignment is to reassign the previous element
When mixing declarations, indexes and associations do not affect each other (do not affect the declaration of index subscript)
2. Using the array () function declaration
The default is an indexed array, if you specify subscripts for associative arrays and indexed arrays, use the key = = value, use "," split between multiple members
3. Use a different function declaration
(1) Indexed array
- $user [0]=1; //user ordinal
- $user [1]= "Zhangsan" ; //user name
- $user [2]=10; //age
- $user [3]= "Nan" ; //sex
- echo '
/pre>
' ;
(2) Associative arrays
- < ' PHP
- $user ["id"]=1;
- $user ["name"]= "Zhangsan" ;
- $user ["age"]=10;
- $user ["Sex"];
- $user ["age"]=90; //Assigned value
- Echo $user["name"]; //Output
- //Use Array () to declare arrays
- $user = Array (1,"Zhangsan", ten,"nan");
- //Use Array () to declare an associative array
- $user = Array ("id"=>1,"name"="zhangsan","age" =>10,"Sex"="nan");
- //Declare multidimensional arrays (multiple records) to hold multiple user information records in a table
- $user = Array (
- call this line with $user[0], such as calling the name in the record, $user [0][1]
- Array (1,"Zhangsan", ten,"nan"),
- call this line with $user[1], such as calling the name in the record, $user [1][1]
- Array (2,"Lisi","NV")
- );
- //Arrays save multiple tables with multiple records per table
- $info = Array (
- "User" = Array (
- Array (1,"Zhangsan", ten,"nan"),
- Array (2,"Lisi","NV")
- ),
- "Score" = Array (
- Array (1,90,80,70),
- Array (2,60,40,70)
- )
- );
- Echo $info["Score"][1][1]; //output,
- ?>
Hope that through the introduction of this article, can bring you help.
http://www.bkjia.com/PHPjc/445774.html www.bkjia.com true http://www.bkjia.com/PHPjc/445774.html techarticle An array is a form in which a number of variables of the same type are organized in an orderly manner in order to deal with them conveniently. The set of these ordered, homogeneous data elements ...