: This article mainly introduces ThinkPHP learning-array learning. For more information about PHP tutorials, see. PHP array
Many similar variables need to be created either early or late during PHP development. Without many similar variables, you can store data as elements in an array. All elements in the array have their own IDs (I .e. subscripts), so they can be easily accessed. There are three types of arrays: 1. value array: an array with the digit ID key; 2. join array: each ID key in the array is associated with a value. 3. multi-dimensional array: an array that contains one or more arrays.
Numeric array
Example 1
In this example, the ID key is automatically assigned:
Example 2
In this example, we manually allocate the ID key:
You can use these ID keys in the script:
Output of the above code: array1 or array2 orarray3 ···
Join array
Join array. each ID key is associated with a value. It is not the best practice to use a numeric array to store data related to specific named values. By associating arrays, we can use values as keys and assign values to them.
Example 1
In this example, we use an array to allocate age to different arrays:
Example 2
This example is the same as example 1, but shows another method to create an array:
You can also use the ID key in the script:
Output of the above script: array1 is 1 number.
Multi-dimensional array
In a multi-dimensional array, each element in the main array is also an array. Each element in the sub-array can also be an array, and so on.
Example 1
In this example, we create a multidimensional array with an automatically assigned ID key:
If this array is output, it should be similar to the following:
The above introduces ThinkPHP learning-array learning, including the content, hope to be helpful to friends who are interested in PHP tutorials.